Skip to main content
Version: Phaser v4.0.0

Phaser.Tweens.Builders

Scope: static

Source: src/tweens/builders/index.js#L7

Static functions

GetBoolean

<static> GetBoolean(source, key, defaultValue)

Description:

Retrieves the boolean value of the given key from a source object, returning a default value if the key is missing or no source object is provided.

Parameters:

nametypeoptionaldescription
sourceobjectNoThe object to retrieve the value from.
keystringNoThe key to look for in the source object.
defaultValuebooleanNoThe default value to return if the key doesn't exist or if no source object is provided.

Returns: boolean - The boolean value associated with the key, or defaultValue if the key does not exist or no source object was provided.

Source: src/tweens/builders/GetBoolean.js#L7
Since: 3.0.0


GetEaseFunction

<static> GetEaseFunction(ease, [easeParams])

Description:

Returns the easing function corresponding to the given ease value for use in a Tween.

The ease argument can be an exact key from the EaseMap (e.g. 'Power2', 'Quad.easeIn'), a shorthand dot-notation string (e.g. 'quad.in', 'cubic.inout'), or a custom easing function. If the string cannot be resolved, the function falls back to Power0 (linear easing).

When easeParams is provided, the returned function is a wrapper that forwards those extra arguments to the resolved ease function on every call, enabling parameterised easings such as Stepped or Back easing.

Parameters:

nametypeoptionaldescription
easestring | functionNoThe ease to resolve. Accepts an EaseMap key, a dot-notation shorthand (e.g. 'quad.in'), or a custom easing function.
easeParamsArray.<number>YesAn optional array of additional parameters to pass to the ease function on each call.

Returns: function - The resolved ease function, or a wrapper function that applies the resolved ease with the provided parameters.

Source: src/tweens/builders/GetEaseFunction.js#L10
Since: 3.0.0


GetInterpolationFunction

<static> GetInterpolationFunction(interpolation)

Description:

Returns the interpolation function to be used by a Tween for multi-value properties.

The interpolation argument can be a string key, a custom function, or null. Valid string keys are 'linear', 'bezier', 'catmull', and 'catmullrom'. If a string is provided but not recognised, the function falls back to linear interpolation. If null is passed, null is returned, indicating no interpolation should be applied. If a custom function is passed, it is returned directly and used as the interpolator.

Parameters:

nametypeoptionaldescription
interpolationstring | functionnullNo

Returns: function - The resolved interpolation function, or null if null was passed in.

Source: src/tweens/builders/GetInterpolationFunction.js#L18
Since: 3.60.0


GetNewValue

<static> GetNewValue(source, key, defaultValue)

Description:

Internal function used by the Tween Builder to create a value resolver callback for a tween property. It inspects the given source object for the specified key and returns a wrapper function suitable for use during tween interpolation. If the property exists on the source and is itself a function, it is wrapped so it receives the full tween context (target, targetKey, value, targetIndex, totalTargets, tween) on each call. If the property is a static value, a function that always returns that value is created instead. If the source does not have the property, the defaultValue is used — either directly (if it is already a function) or wrapped in a function that returns it.

Parameters:

nametypeoptionaldescription
sourceanyNoThe source object to get the value from.
keystringNoThe property to get from the source.
defaultValueanyNoA default value to use should the source not have the property set. May itself be a function.

Returns: function - A function which, when called, returns the resolved property value from the source, or the default value if the property is not present.

Source: src/tweens/builders/GetNewValue.js#L7
Since: 3.0.0


GetProps

<static> GetProps(config)

Description:

Internal function used by the Tween Builder to extract the list of properties that the Tween will animate. It takes a Tween configuration object and follows one of two paths: if the config contains a props object, it iterates its keys and skips any that begin with an underscore; otherwise, it iterates the top-level config keys directly, skipping both any that begin with an underscore and any that appear on the Reserved Properties list (e.g. targets, delay, duration).

Parameters:

nametypeoptionaldescription
configPhaser.Types.Tweens.TweenBuilderConfigNoThe configuration object of the Tween to get the properties from.

Returns: Array.<string> - An array of { key, value } objects representing each property the tween will animate.

Source: src/tweens/builders/GetProps.js#L9
Since: 3.0.0


GetTargets

<static> GetTargets(config)

Description:

Extracts an array of targets from a Tween configuration object.

The targets will be looked for in a targets property. If it's a function, its return value will be used as the result.

Parameters:

nametypeoptionaldescription
configobjectNoThe Tween configuration object containing the targets property to extract.

Returns: array - An array of targets (may contain only one element), or null if no targets were specified.

Source: src/tweens/builders/GetTargets.js#L9
Since: 3.0.0


GetValueOp

<static> GetValueOp(key, propertyValue)

Description:

Returns getActive, getStart and getEnd functions for a TweenData based on a target property and end value.

getActive if not null, is invoked immediately as soon as the TweenData is running, and is set on the target property. getEnd is invoked once any start delays have expired and returns what the value should tween to. getStart is invoked when the tween reaches the end and needs to either repeat or yoyo, it returns the value to go back to.

If the end value is a number, it will be treated as an absolute value and the property will be tweened to it. A string can be provided to specify a relative end value which consists of an operation (+= to add to the current value, -= to subtract from the current value, *= to multiply the current value, or /= to divide the current value) followed by its operand.

A function can be provided to allow greater control over the end value; it will receive the target object being tweened, the name of the property being tweened, and the current value of the property as its arguments and must return a value.

If both the starting and the ending values need to be controlled, an object with getStart and getEnd callbacks, which will receive the same arguments, can be provided instead. If an object with a value property is provided, the property will be used as the effective value under the same rules described here.

Parameters:

nametypeoptionaldescription
keystringNoThe name of the property to modify.
propertyValue*NoThe ending value of the property, as described above.

Returns: function - An object containing getActive, getStart, and getEnd functions, which return the active, starting, and ending values of the property based on the provided value.

Source: src/tweens/builders/GetValueOp.js#L42
Since: 3.0.0


NumberTweenBuilder

<static> NumberTweenBuilder(parent, config, defaults)

Description:

Creates a new Number Tween, also known as a counter tween.

Unlike a standard tween, a Number Tween does not target a Game Object's properties. Instead, it interpolates a plain numeric value between a from and a to value over the course of the tween. The current interpolated value can be read at any time via tween.getValue(). This makes Number Tweens ideal for driving custom animations, UI counters, shader uniforms, or any other value that needs to change smoothly over time without being tied directly to a Game Object property.

Parameters:

nametypeoptionaldescription
parentPhaser.Tweens.TweenManagerNoThe owner of the new Tween.
configPhaser.Types.Tweens.NumberTweenBuilderConfigNoConfiguration for the new Tween.
defaultsPhaser.Types.Tweens.TweenConfigDefaultsNoTween configuration defaults.

Returns: Phaser.Tweens.Tween - The new tween.

Source: src/tweens/builders/NumberTweenBuilder.js#L19
Since: 3.0.0


StaggerBuilder

<static> StaggerBuilder(value, [options])

Description:

Creates a Stagger function to be used by a Tween property.

The stagger function will allow you to stagger changes to the value of the property across all targets of the tween.

This is only worth using if the tween has multiple targets.

The following will stagger the delay by 100ms across all targets of the tween, causing them to scale down to 0.2 over the duration specified:


this.tweens.add({

targets: [ ... ],

scale: 0.2,

ease: 'linear',

duration: 1000,

delay: this.tweens.stagger(100)

});

The following will stagger the delay by 500ms across all targets of the tween using a 10 x 6 grid, staggering from the center out, using a cubic ease.


this.tweens.add({

targets: [ ... ],

scale: 0.2,

ease: 'linear',

duration: 1000,

delay: this.tweens.stagger(500, { grid: [ 10, 6 ], from: 'center', ease: 'cubic.out' })

});

Parameters:

nametypeoptionaldescription
valuenumber | Array.<number>NoThe amount to stagger by, or an array containing two elements representing the min and max values to stagger between.
optionsPhaser.Types.Tweens.StaggerConfigYesA Stagger Configuration object.

Returns: function - A stagger function that, when invoked by the Tween system for each target, calculates and returns the staggered property value for that target based on its index, the total number of targets, and the stagger configuration provided.

Source: src/tweens/builders/StaggerBuilder.js#L11
Since: 3.19.0


TweenBuilder

<static> TweenBuilder(parent, config, defaults)

Description:

Parses a Tween configuration object and constructs a fully initialized Tween instance ready to be added to the Tween Manager.

This builder resolves the list of targets and properties from the config, creates a TweenData entry for every target/property combination, and applies default values for easing, duration, delay, hold, repeat, yoyo, flip, and interpolation. A special scale shortcut is supported: if a target does not have a native scale property, the builder automatically expands it into separate scaleX and scaleY TweenData entries. Texture tweening (changing a target's texture and frame over time) is also handled as a distinct code path.

After building the TweenData entries, the builder configures top-level Tween properties such as loop, loopDelay, completeDelay, paused, persist, and any callbacks defined in the config (e.g. onStart, onUpdate, onComplete).

If config is already a Tween instance, its parent is updated and it is returned as-is without further processing.

Parameters:

nametypeoptionaldescription
parentPhaser.Tweens.TweenManagerNoThe owner of the new Tween.
configPhaser.Types.Tweens.TweenBuilderConfig | objectNoConfiguration for the new Tween.
defaultsPhaser.Types.Tweens.TweenConfigDefaultsNoTween configuration defaults.

Returns: Phaser.Tweens.Tween - The new tween.

Source: src/tweens/builders/TweenBuilder.js#L22
Since: 3.0.0


TweenChainBuilder

<static> TweenChainBuilder(parent, config)

Description:

Creates a new TweenChain instance from the given configuration object. A TweenChain is a sequence of Tweens that play one after another in order, rather than all at once. This makes it useful for creating multi-step animations where each step must complete before the next begins.

This builder is called internally by the TweenManager when you use scene.tweens.chain(). It processes the config object to set up the chain's start delay, loop count, loop delay, completion delay, paused state, lifecycle callbacks, and the individual Tweens that make up the chain. If any top-level targets are defined in the config, they are passed as defaults to each child Tween that does not specify its own targets.

If the config argument is already a TweenChain instance, its parent is updated and it is returned as-is without rebuilding.

Parameters:

nametypeoptionaldescription
parentPhaser.Tweens.TweenManagerNoThe owner of the new Tween.
configPhaser.Types.Tweens.TweenChainBuilderConfig | objectNoConfiguration for the new Tween.

Returns: Phaser.Tweens.TweenChain - The new Tween Chain.

Source: src/tweens/builders/TweenChainBuilder.js#L15
Since: 3.60.0