A simple manager for tracking and updating game tween objects. Normally accessed via the static FlxTween.globalManager rather than being created separately.

Constructor

new()

Methods

@:value({ Duration : 1 })angle(?Sprite:FlxSprite, FromAngle:Float, ToAngle:Float, Duration:Float = 1, ?Options:Null<TweenOptions>):AngleTween

Tweens numeric value which represents angle. Shorthand for creating a AngleTween object, starting it and adding it to the TweenManager.

FlxTween.angle(Sprite, -90, 90, 2.0, { ease: easeFunction, onStart: onStart, onUpdate: onUpdate, onComplete: onComplete, type: ONESHOT });

Parameters:

Sprite

Optional Sprite whose angle should be tweened.

FromAngle

Start angle.

ToAngle

End angle.

Duration

Duration of the tween.

Options

A structure with tween options.

Returns:

The added AngleTween object.

Available since

4.2.0

.

cancelTweensOf(Object:Dynamic, ?FieldPaths:Array<String>):Void

Cancels all related tweens on the specified object.

Note: Any tweens with the specified fields are cancelled, if the tween has other properties they will also be cancelled.

Parameters:

Object

The object with tweens to cancel.

FieldPaths

Optional list of the tween field paths to search for. If null or empty, all tweens on the specified object are canceled. Allows dot paths to check child properties.

Available since

4.9.0

.

@:value({ UseDuration : true, DurationOrSpeed : 1 })circularMotion(Object:FlxObject, CenterX:Float, CenterY:Float, Radius:Float, Angle:Float, Clockwise:Bool, DurationOrSpeed:Float = 1, UseDuration:Bool = true, ?Options:Null<TweenOptions>):CircularMotion

Create a new CircularMotion tween.

FlxTween.circularMotion(Object, 250, 250, 50, 0, true, 2, true, { ease: easeFunction, onStart: onStart, onUpdate: onUpdate, onComplete: onComplete, type: ONESHOT });

Parameters:

Object

The object to move (FlxObject or FlxSpriteGroup)

CenterX

X position of the circle's center.

CenterY

Y position of the circle's center.

Radius

Radius of the circle.

Angle

Starting position on the circle.

Clockwise

If the motion is clockwise.

DurationOrSpeed

Duration of the movement in seconds.

UseDuration

Duration of the movement.

Ease

Optional easer function.

Options

A structure with tween options.

Returns:

The CircularMotion object.

Available since

4.2.0

.

clear():Void

Removes all FlxTweens.

@:value({ Duration : 1 })color(?Sprite:FlxSprite, Duration:Float = 1, FromColor:FlxColor, ToColor:FlxColor, ?Options:Null<TweenOptions>):ColorTween

Tweens numeric value which represents color. Shorthand for creating a ColorTween object, starting it and adding it to a TweenPlugin.

FlxTween.color(Sprite, 2.0, 0x000000, 0xffffff, 0.0, 1.0, { ease: easeFunction, onStart: onStart, onUpdate: onUpdate, onComplete: onComplete, type: ONESHOT });

Parameters:

Sprite

Optional Sprite whose color should be tweened.

Duration

Duration of the tween in seconds.

FromColor

Start color.

ToColor

End color.

Options

A structure with tween options.

Returns:

The added ColorTween object.

Available since

4.2.0

.

completeAll():Void

Immediately updates all tweens that are not looping (type FlxTween.LOOPING or FlxTween.PINGPONG) and active through their endings, triggering their onComplete callbacks.

Note: if they haven't yet begun, this will first trigger their onStart callback.

Note: their onComplete callbacks are triggered in the next frame. To trigger them immediately, call FlxTween.globalManager.update(0); after this function.

In no case should it trigger an onUpdate callback.

Available since

4.2.0

.

completeTweensOf(Object:Dynamic, ?FieldPaths:Array<String>):Void

Immediately updates all tweens on the specified object with the specified fields that are not looping (type FlxTween.LOOPING or FlxTween.PINGPONG) and active through their endings, triggering their onComplete callbacks.

Note: if they haven't yet begun, this will first trigger their onStart callback.

Note: their onComplete callbacks are triggered in the next frame. To trigger them immediately, call FlxTween.globalManager.update(0); after this function.

In no case should it trigger an onUpdate callback.

Note: Any tweens with the specified fields are completed, if the tween has other properties they will also be completed.

Parameters:

Object

The object with tweens to complete.

FieldPaths

Optional list of the tween field paths to search for. If null or empty, all tweens on the specified object are completed. Allows dot paths to check child properties.

Available since

4.9.0

.

@:value({ Duration : 1 })cubicMotion(Object:FlxObject, FromX:Float, FromY:Float, aX:Float, aY:Float, bX:Float, bY:Float, ToX:Float, ToY:Float, Duration:Float = 1, ?Options:Null<TweenOptions>):CubicMotion

Create a new CubicMotion tween.

FlxTween.cubicMotion(_sprite, 0, 0, 500, 100, 400, 200, 100, 100, 2, { ease: easeFunction, onStart: onStart, onUpdate: onUpdate, onComplete: onComplete, type: ONESHOT });

Parameters:

Object

The object to move (FlxObject or FlxSpriteGroup)

FromX

X start.

FromY

Y start.

aX

First control x.

aY

First control y.

bX

Second control x.

bY

Second control y.

ToX

X finish.

ToY

Y finish.

Duration

Duration of the movement in seconds.

Options

A structure with tween options.

Returns:

The CubicMotion object.

Available since

4.2.0

.

forEach(Function:FlxTween ‑> Void):Void

Applies a function to all tweens

Parameters:

Function

A function that modifies one tween at a time

Available since

4.2.0

.

@:value({ UseDuration : true, DurationOrSpeed : 1 })linearMotion(Object:FlxObject, FromX:Float, FromY:Float, ToX:Float, ToY:Float, DurationOrSpeed:Float = 1, UseDuration:Bool = true, ?Options:Null<TweenOptions>):LinearMotion

Create a new LinearMotion tween.

FlxTween.linearMotion(Object, 0, 0, 500, 20, 5, false, { ease: easeFunction, onStart: onStart, onUpdate: onUpdate, onComplete: onComplete, type: ONESHOT });

Parameters:

Object

The object to move (FlxObject or FlxSpriteGroup)

FromX

X start.

FromY

Y start.

ToX

X finish.

ToY

Y finish.

DurationOrSpeed

Duration (in seconds) or speed of the movement.

UseDuration

Whether to use the previous param as duration or speed.

Options

A structure with tween options.

Returns:

The LinearMotion object.

Available since

4.2.0

.

@:value({ UseDuration : true, DurationOrSpeed : 1 })linearPath(Object:FlxObject, Points:Array<FlxPoint>, DurationOrSpeed:Float = 1, UseDuration:Bool = true, ?Options:Null<TweenOptions>):LinearPath

Create a new LinearPath tween.

FlxTween.linearPath(Object, [FlxPoint.get(0, 0), FlxPoint.get(100, 100)], 2, true, { ease: easeFunction, onStart: onStart, onUpdate: onUpdate, onComplete: onComplete, type: ONESHOT });

Parameters:

Object

The object to move (FlxObject or FlxSpriteGroup)

Points

An array of at least 2 FlxPoints defining the path

DurationOrSpeed

Duration (in seconds) or speed of the movement.

UseDuration

Whether to use the previous param as duration or speed.

Options

A structure with tween options.

Returns:

The LinearPath object.

Available since

4.2.0

.

@:value({ Duration : 1 })num(FromValue:Float, ToValue:Float, Duration:Float = 1, ?Options:Null<TweenOptions>, ?TweenFunction:Float ‑> Void):NumTween

Tweens some numeric value. Shorthand for creating a NumTween, starting it and adding it to the TweenManager. Using it in conjunction with a TweenFunction requires more setup, but is faster than VarTween because it doesn't use Reflection.

function tweenFunction(s:FlxSprite, v:Float) { s.alpha = v; }
FlxTween.num(1, 0, 2.0, { ease: easeFunction, onStart: onStart, onUpdate: onUpdate, onComplete: onComplete, type: ONESHOT }, tweenFunction.bind(mySprite));

Trivia: For historical reasons, you can use either onUpdate or TweenFunction to accomplish the same thing, but TweenFunction gives you the updated Float as a direct argument.

Parameters:

FromValue

Start value.

ToValue

End value.

Duration

Duration of the tween.

Options

A structure with tween options.

TweenFunction

A function to be called when the tweened value updates. It is recommended not to use an anonymous function if you are maximizing performance, as those will be compiled to Dynamics on cpp.

Returns:

The added NumTween object.

Available since

4.2.0

.

@:value({ UseDuration : true, DurationOrSpeed : 1 })quadMotion(Object:FlxObject, FromX:Float, FromY:Float, ControlX:Float, ControlY:Float, ToX:Float, ToY:Float, DurationOrSpeed:Float = 1, UseDuration:Bool = true, ?Options:Null<TweenOptions>):QuadMotion

Create a new QuadMotion tween.

FlxTween.quadMotion(Object, 0, 100, 300, 500, 100, 2, 5, false, { ease: easeFunction, onStart: onStart, onUpdate: onUpdate, onComplete: onComplete, type: ONESHOT });

Parameters:

Object

The object to move (FlxObject or FlxSpriteGroup)

FromX

X start.

FromY

Y start.

ControlX

X control, used to determine the curve.

ControlY

Y control, used to determine the curve.

ToX

X finish.

ToY

Y finish.

DurationOrSpeed

Duration (in seconds) or speed of the movement.

UseDuration

Whether to use the previous param as duration or speed.

Options

A structure with tween options.

Returns:

The QuadMotion object.

Available since

4.2.0

.

@:value({ UseDuration : true, DurationOrSpeed : 1 })quadPath(Object:FlxObject, Points:Array<FlxPoint>, DurationOrSpeed:Float = 1, UseDuration:Bool = true, ?Options:Null<TweenOptions>):QuadPath

Create a new QuadPath tween.

FlxTween.quadPath(Object, [FlxPoint.get(0, 0), FlxPoint.get(200, 200), FlxPoint.get(400, 0)], 2, true, { ease: easeFunction, onStart: onStart, onUpdate: onUpdate, onComplete: onComplete, type: ONESHOT });

Parameters:

Object

The object to move (FlxObject or FlxSpriteGroup)

Points

An array of at least 3 FlxPoints defining the path

DurationOrSpeed

Duration (in seconds) or speed of the movement.

UseDuration

Whether to use the previous param as duration or speed.

Options

A structure with tween options.

Returns:

The QuadPath object.

Available since

4.2.0

.

@:value({ Axes : XY, Duration : 1, Intensity : 0.05 })shake(Sprite:FlxSprite, Intensity:Float = 0.05, Duration:Float = 1, Axes:FlxAxes = XY, ?Options:Null<TweenOptions>):ShakeTween

A simple shake effect for FlxSprite. Shorthand for creating a ShakeTween, starting it and adding it to the TweenManager.

FlxTween.shake(Sprite, 0.1, 2, FlxAxes.XY, { ease: easeFunction, onStart: onStart, onUpdate: onUpdate, onComplete: onComplete, type: ONESHOT });

Parameters:

Sprite

Sprite to shake.

Intensity

Percentage representing the maximum distance that the sprite can move while shaking.

Duration

The length in seconds that the shaking effect should last.

Axes

On what axes to shake. Default value is FlxAxes.XY / both.

Options

A structure with tween options.

@:value({ Duration : 1 })tween(Object:Dynamic, Values:Dynamic, Duration:Float = 1, ?Options:Null<TweenOptions>):VarTween

Tweens numeric public properties of an Object. Shorthand for creating a VarTween, starting it and adding it to the TweenManager.

FlxTween.tween(Object, { x: 500, y: 350, "scale.x": 2 }, 2.0, { ease: easeFunction, onStart: onStart, onUpdate: onUpdate, onComplete: onComplete, type: ONESHOT });

Parameters:

Object

The object containing the properties to tween.

Values

An object containing key/value pairs of properties and target values.

Duration

Duration of the tween in seconds.

Options

A structure with tween options.

Returns:

The added VarTween object.

Available since

4.2.0

.

Inherited Variables

Defined by FlxBasic

@:value(idEnumerator++)ID:Int = idEnumerator++

A unique ID starting from 0 and increasing by 1 for each subsequent FlxBasic that is created.

@:value(true)active:Bool = true

Controls whether update() is automatically called by FlxState/FlxGroup.

@:value(true)alive:Bool = true

Useful state for many game objects - "dead" (!alive) vs alive. kill() and revive() both flip this switch (along with exists, but you can override that).

camera:FlxCamera

Gets or sets the first camera of this object.

cameras:Array<FlxCamera>

This determines on which FlxCameras this object will be drawn. If it is null / has not been set, it uses the list of default draw targets, which is controlled via FlxG.camera.setDefaultDrawTarget as well as the DefaultDrawTarget argument of FlxG.camera.add.

@:value(true)exists:Bool = true

Controls whether update() and draw() are automatically called by FlxState/FlxGroup.

@:value(true)visible:Bool = true

Controls whether draw() is automatically called by FlxState/FlxGroup.

Inherited Methods

Defined by FlxBasic

draw():Void

Override this function to control how the object is drawn. Doing so is rarely necessary, but can be very useful.

kill():Void

Handy function for "killing" game objects. Use reset() to revive them. Default behavior is to flag them as nonexistent AND dead. However, if you want the "corpse" to remain in the game, like to animate an effect or whatever, you should override this, setting only alive to false, and leaving exists true.

revive():Void

Handy function for bringing game objects "back to life". Just sets alive and exists back to true. In practice, this function is most often called by FlxObject#reset().