Skip to main content
Version: Phaser v4.0.0

Phaser.GameObjects

Scope: static

Source: src/gameobjects/index.js#L7

Static functions

Static functions

BuildGameObject

<static> BuildGameObject(scene, gameObject, config)

Description:

Builds a Game Object using the provided configuration object, applying properties such as position, depth, flip, scale, scroll factor, rotation, alpha, origin, blend mode, and visibility. If the config's add property is true (the default), the Game Object is added to the Scene's Display List. If the Game Object has a preUpdate method it is also added to the Scene's Update List. This function is used internally by Game Object factories and creators, and is not typically called directly.

Parameters:

nametypeoptionaldescription
scenePhaser.SceneNoA reference to the Scene.
gameObjectPhaser.GameObjects.GameObjectNoThe initial GameObject.
configPhaser.Types.GameObjects.GameObjectConfigNoThe config to build the GameObject with.

Returns: Phaser.GameObjects.GameObject - The built Game Object.

Source: src/gameobjects/BuildGameObject.js#L10
Since: 3.0.0


BuildGameObjectAnimation

<static> BuildGameObjectAnimation(sprite, config)

Description:

Reads the anims property from a Game Object configuration object and uses it to configure the animation state of the given Sprite. If the anims property is absent, the Sprite is returned unchanged.

The anims value may be either a string or an object. If it is a string, it is treated as an animation key and the animation is played immediately. If it is an object, the animation key and playback options (such as delay, repeat, yoyo, and startFrame) are read from it. Depending on the play and delayedPlay properties, the animation will be played immediately, played after a delay, or simply loaded ready to play later.

Parameters:

nametypeoptionaldescription
spritePhaser.GameObjects.SpriteNoThe Sprite whose animation state will be configured.
configobjectNoThe Game Object configuration object. The anims property of this object is used to configure the animation.

Returns: Phaser.GameObjects.Sprite - The updated Sprite.

Source: src/gameobjects/BuildGameObjectAnimation.js#L9
Since: 3.0.0


GetCalcMatrix

<static> GetCalcMatrix(src, camera, [parentMatrix], [ignoreCameraPosition])

Description:

Calculates the Transform Matrix of the given Game Object and Camera, factoring in the parent matrix if provided.

Note that the object this result contains references to the Transform Matrices, not new instances of them. Therefore, you should use their values immediately, or copy them to your own matrix, as they will be replaced as soon as another Game Object is rendered.

Parameters:

nametypeoptionaldefaultdescription
srcPhaser.GameObjects.GameObjectNoThe Game Object to calculate the transform matrix for.
cameraPhaser.Cameras.Scene2D.CameraNoThe camera being used to render the Game Object.
parentMatrixPhaser.GameObjects.Components.TransformMatrixYesThe transform matrix of the parent container, if any.
ignoreCameraPositionbooleanYesfalseShould the camera's translation be ignored? This is what moves a camera around on the screen, but it should be ignored when the camera is being rendered to a framebuffer.

Returns: Phaser.Types.GameObjects.GetCalcMatrixResults - The results object containing the updated transform matrices.

Source: src/gameobjects/GetCalcMatrix.js#L21
Since: 3.50.0


GetTextSize

<static> GetTextSize(text, size, lines)

Description:

Calculates and returns the rendered dimensions of a Text object, including the width of each line, the maximum line width, the total height (accounting for line spacing), and the number of drawn lines (respecting maxLines).

Parameters:

nametypeoptionaldescription
textPhaser.GameObjects.TextNoThe Text object to calculate the size from.
sizePhaser.Types.GameObjects.Text.TextMetricsNoThe Text metrics to use when calculating the size.
linesArray.<string>NoThe lines of text to calculate the size from.

Returns: Phaser.Types.GameObjects.Text.GetTextSizeObject - An object containing dimensions of the Text object.

Source: src/gameobjects/text/GetTextSize.js#L7
Since: 3.0.0


MeasureText

<static> MeasureText(textStyle)

Description:

Calculates the ascent, descent, and fontSize metrics for a given TextStyle by rendering text to a temporary offscreen canvas and measuring the pixel boundaries. It uses the actualBoundingBoxAscent/actualBoundingBoxDescent API where available, falling back to a pixel-scanning approach for older browsers.

Parameters:

nametypeoptionaldescription
textStylePhaser.GameObjects.TextStyleNoThe TextStyle object to measure.

Returns: Phaser.Types.GameObjects.Text.TextMetrics - An object containing the ascent, descent and fontSize of the TextStyle.

Source: src/gameobjects/text/MeasureText.js#L9
Since: 3.0.0


Static functions