class flixel.util.FlxVelocity
Available on all platforms
Class Fields
static function accelerateTowardsMouse(Source:FlxSprite, Speed:Int, MaxXSpeed:Int, MaxYSpeed:Int):Void
Sets the x/y acceleration on the source FlxSprite so it will move towards the mouse coordinates at the speed given (in pixels per second) * You must give a maximum speed value, beyond which the FlxSprite won't go any faster. * If you don't need acceleration look at moveTowardsMouse() instead. * *
Source | The FlxSprite on which the acceleration will be set * |
Speed | The speed it will accelerate in pixels per second * |
MaxXSpeed | The maximum speed in pixels per second in which the sprite can move horizontally * |
MaxYSpeed | The maximum speed in pixels per second in which the sprite can move vertically |
static function accelerateTowardsObject(Source:FlxSprite, Dest:FlxSprite, Speed:Int, MaxXSpeed:Int, MaxYSpeed:Int):Void
Sets the x/y acceleration on the source FlxSprite so it will move towards the destination FlxSprite at the speed given (in pixels per second) * You must give a maximum speed value, beyond which the FlxSprite won't go any faster. * If you don't need acceleration look at moveTowardsObject() instead. * *
Source | The FlxSprite on which the acceleration will be set * |
Dest | The FlxSprite where the source object will move towards * |
Speed | The speed it will accelerate in pixels per second * |
MaxXSpeed | The maximum speed in pixels per second in which the sprite can move horizontally * |
MaxYSpeed | The maximum speed in pixels per second in which the sprite can move vertically |
static function accelerateTowardsPoint(Source:FlxSprite, Target:FlxPoint, Speed:Int, MaxXSpeed:Int, MaxYSpeed:Int):Void
Sets the x/y acceleration on the source FlxSprite so it will move towards the target coordinates at the speed given (in pixels per second) * You must give a maximum speed value, beyond which the FlxSprite won't go any faster. * If you don't need acceleration look at moveTowardsPoint() instead. * *
Source | The FlxSprite on which the acceleration will be set * |
Target | The FlxPoint coordinates to move the source FlxSprite towards * |
Speed | The speed it will accelerate in pixels per second * |
MaxXSpeed | The maximum speed in pixels per second in which the sprite can move horizontally * |
MaxYSpeed | The maximum speed in pixels per second in which the sprite can move vertically |
static function accelerateTowardsTouch(Source:FlxSprite, Touch:FlxTouch, Speed:Int, MaxXSpeed:Int, MaxYSpeed:Int):Void
Sets the x/y acceleration on the source FlxSprite so it will move towards a FlxTouch at the speed given (in pixels per second) * You must give a maximum speed value, beyond which the FlxSprite won't go any faster. * If you don't need acceleration look at moveTowardsMouse() instead. * *
Source | The FlxSprite on which the acceleration will be set * |
Touch | The FlxTouch on which to accelerate towards * |
Speed | The speed it will accelerate in pixels per second * |
MaxXSpeed | The maximum speed in pixels per second in which the sprite can move horizontally * |
MaxYSpeed | The maximum speed in pixels per second in which the sprite can move vertically |
static function computeVelocity(Velocity:Float, Acceleration:Float, Drag:Float, Max:Float):Float
A tween-like function that takes a starting velocity and some other factors and returns an altered velocity. * *
Velocity | Any component of velocity (e.g. 20). * |
Acceleration | Rate at which the velocity is changing. * |
Drag | Really kind of a deceleration, this is how much the velocity changes if Acceleration is not set. * |
Max | An absolute value cap for the velocity (0 for no cap). * |
returns | The altered Velocity value. |
static function moveTowardsMouse(Source:FlxSprite, ?Speed:Int = 60, ?MaxTime:Int = 0):Void
Move the given FlxSprite towards the mouse pointer coordinates at a steady velocity * If you specify a maxTime then it will adjust the speed (over-writing what you set) so it arrives at the destination in that number of seconds. * Timings are approximate due to the way Flash timers work, and irrespective of SWF frame rate. Allow for a variance of +- 50ms. * The source object doesn't stop moving automatically should it ever reach the destination coordinates. * *
Source | The FlxSprite to move * |
Speed | The speed it will move, in pixels per second (default is 60 pixels/sec) * |
MaxTime | Time given in milliseconds (1000 = 1 sec). If set the speed is adjusted so the source will arrive at destination in the given number of ms |
static function moveTowardsObject(Source:FlxSprite, Dest:FlxSprite, ?Speed:Int = 60, ?MaxTime:Int = 0):Void
Sets the source FlxSprite x/y velocity so it will move directly towards the destination FlxSprite at the speed given (in pixels per second) * If you specify a maxTime then it will adjust the speed (over-writing what you set) so it arrives at the destination in that number of seconds. * Timings are approximate due to the way Flash timers work, and irrespective of SWF frame rate. Allow for a variance of +- 50ms. * The source object doesn't stop moving automatically should it ever reach the destination coordinates. * If you need the object to accelerate, see accelerateTowardsObject() instead * Note: Doesn't take into account acceleration, maxVelocity or drag (if you set drag or acceleration too high this object may not move at all) * *
Source | The FlxSprite on which the velocity will be set * |
Dest | The FlxSprite where the source object will move to * |
Speed | The speed it will move, in pixels per second (default is 60 pixels/sec) * |
MaxTime | Time given in milliseconds (1000 = 1 sec). If set the speed is adjusted so the source will arrive at destination in the given number of ms |
static function moveTowardsPoint(Source:FlxSprite, Target:FlxPoint, ?Speed:Int = 60, ?MaxTime:Int = 0):Void
Sets the x/y velocity on the source FlxSprite so it will move towards the target coordinates at the speed given (in pixels per second) * If you specify a maxTime then it will adjust the speed (over-writing what you set) so it arrives at the destination in that number of seconds. * Timings are approximate due to the way Flash timers work, and irrespective of SWF frame rate. Allow for a variance of +- 50ms. * The source object doesn't stop moving automatically should it ever reach the destination coordinates. * *
Source | The FlxSprite to move * |
Target | The FlxPoint coordinates to move the source FlxSprite towards * |
Speed | The speed it will move, in pixels per second (default is 60 pixels/sec) * |
MaxTime | Time given in milliseconds (1000 = 1 sec). If set the speed is adjusted so the source will arrive at destination in the given number of ms |
static function moveTowardsTouch(Source:FlxSprite, Touch:FlxTouch, ?Speed:Int = 60, ?MaxTime:Int = 0):Void
Move the given FlxSprite towards a FlxTouch point at a steady velocity * If you specify a maxTime then it will adjust the speed (over-writing what you set) so it arrives at the destination in that number of seconds. * Timings are approximate due to the way Flash timers work, and irrespective of SWF frame rate. Allow for a variance of +- 50ms. * The source object doesn't stop moving automatically should it ever reach the destination coordinates. * *
source | The FlxSprite to move * |
speed | The speed it will move, in pixels per second (default is 60 pixels/sec) * |
maxTime | Time given in milliseconds (1000 = 1 sec). If set the speed is adjusted so the source will arrive at destination in the given number of ms |
static function velocityFromAngle(Angle:Int, Speed:Int):FlxPoint
Given the angle and speed calculate the velocity and return it as an FlxPoint * *
Angle | The angle (in degrees) calculated in clockwise positive direction (down = 90 degrees positive, right = 0 degrees positive, up = 90 degrees negative) * |
Speed | The speed it will move, in pixels per second sq * |
returns | A FlxPoint where FlxPoint.x contains the velocity x value and FlxPoint.y contains the velocity y value |
static function velocityFromFacing(Parent:FlxSprite, Speed:Int):FlxPoint
Given the FlxSprite and speed calculate the velocity and return it as an FlxPoint based on the direction the sprite is facing * *
Parent | The FlxSprite to get the facing value from * |
Speed | The speed it will move, in pixels per second * |
returns | An FlxPoint where FlxPoint.x contains the velocity x value and FlxPoint.y contains the velocity y value |