Skip to content

Instantly share code, notes, and snippets.

@caubry
Last active December 17, 2015 20:59
Show Gist options
  • Select an option

  • Save caubry/5671460 to your computer and use it in GitHub Desktop.

Select an option

Save caubry/5671460 to your computer and use it in GitHub Desktop.
Snippet to calculate xSpeed depending on distance travelled and time given in milliseconds.
private static var FPS:Number = 25;
private var movingMc:MovieClip
private var stillMc:MovieClip
private var orignalXPos:Number = 0;
// Set a default value if setter isn't being called
private var xSpeed:Number = 2;
// Constructor
public function CustomSpeed():void
{
orignalXPos = movingMc.x;
}
// Setter function
public function set _speed( timeMS:Number ):void
{
var distance:Number = Math.abs( orignalXPos - stillMc.x );
var time:Number = ( timeMS / 1000 ) * FPS;
xSpeed = distance / time;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment