Quantcast
Channel: Adobe Community : All Content - Edge Animate
Viewing all articles
Browse latest Browse all 9897

Movement/Collision Detection

$
0
0

I am having a hard time trying to figure this one out and was wondering if you can help me?

 

 

I made a square on the stage and named it "player". Then on my Stage actions for document.keydown I wrote:

 

 

if (e.which == 40) { //down

          sym.$("player").animate({top: "+=50"},0);

}

 

 

if (e.which == 38) { //up

          sym.$("player").animate({top: "-=50"},0);

}

 

 

if (e.which == 37) { //left

          sym.$("player").animate({left: "-=50"},0);

}

 

 

if (e.which == 39) { //right

          sym.$("player").animate({left: "+=50"},0);

}

 

 

 

 

This animates the square to move according to the keys pressed. But the thing is I set the duration time to 0 because I noticed that if I set it to say 1000 and pressed a key multiple times while it is still animating that .animate will stack up and play after the oldest one is finished.

 

 

Question 1: How do I make it so that while "player" is still animating to the next position pressing a movement key will not queue up to play the next animation?

 

 

Question 2: Is there a way to make it so that while the key is held it will move in that direction until it is released? (might involve a different library?)

 

 

Question 3: Is there a way to detect collision so that "player" will not go through another <div>/Symbol, also setting the stage as a boundary? (this illustrates the point http://www.youtube.com/watch?v=Q_VmbMQyXj0)


Viewing all articles
Browse latest Browse all 9897

Trending Articles