Skip to content

Determining Velocity

by Colin on May 20th, 2009

A few months ago I wanted to write down a little bit of code to remember how to determine velocity (because I knew I’d have to remember sooner or later. It’s really quite simple, you just need to compare 2 (or more values). Here’s one way you can do it…

Code to determine velocity:

  1. var pX:int;
  2. var pY:int;
  3. var cX:int;
  4. var cY:int;
  6. stage.addEventListener (Event.ENTER_FRAME, getVelocity);
  8. function getVelocity (e:Event) : void {
  9. cX = -pX + (pX = stage.mouseX);
  10. cY = -pY + (pY = stage.mouseY);
  11. }

From → Flash

No comments yet

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS