Last active
March 9, 2023 04:17
-
-
Save therabbitwindfall/8eca8f4c4dcb62387bb6620bb3cff4df to your computer and use it in GitHub Desktop.
Говносвайп для CreateJS | Swipe for CreateJS. Used for Animate CC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| createjs.Touch.enable(stage); | |
| var box = this.box; | |
| box.isDown = false; | |
| box.addEventListener('mousedown', MouseDownAction); | |
| stage.addEventListener('stagemouseup', MouseUpAction); | |
| function MouseDownAction(event){ | |
| box.prevInteraction = new Date().getTime(); | |
| box.prevStageX = event.stageX; | |
| box.prevStageY = event.stageY; | |
| box.isDown = true; | |
| } | |
| function MouseUpAction(event){ | |
| if(box.isDown){ | |
| var dx = event.stageX - box.prevStageX; | |
| var dy = event.stageY - box.prevStageY; | |
| var distance = Math.sqrt(dx*dx+dy*dy); | |
| if(distance!=0){ | |
| var deltaTime = new Date().getTime() - box.prevInteraction; | |
| var speed = distance / deltaTime; | |
| if (speed>2.5){ | |
| swipe(box,dx>0?1:-1); | |
| } | |
| } | |
| box.isDown=false; | |
| } | |
| } | |
| function swipe(sender,direction){ | |
| sender.x += 100 * direction; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment