Phaser.GameObjects.GameObjectFactory
register
<static> register(factoryType, factoryFunction)
Description:
Registers a Game Object factory function on the GameObjectFactory prototype, making it available for creating Game Objects via the Scene's add property.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| factoryType | string | No | The key under which the factory will be registered, accessible as Phaser.Scene.add[factoryType]. |
| factoryFunction | function | No | The factory function to be called when Phaser.Scene.add[factoryType] is invoked. |
Source: src/gameobjects/GameObjectFactory.js#L186
Since: 3.0.0
remove
<static> remove(factoryType)
Description:
Removes a Game Object factory function from the GameObjectFactory prototype.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| factoryType | string | No | The key of the factory that you want to remove from the GameObjectFactory. |
Source: src/gameobjects/GameObjectFactory.js#L205
Since: 3.0.0
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:
| name | type | optional | description |
|---|---|---|---|
| scene | Phaser.Scene | No | A reference to the Scene. |
| gameObject | Phaser.GameObjects.GameObject | No | The initial GameObject. |
| config | Phaser.Types.GameObjects.GameObjectConfig | No | The 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:
| name | type | optional | description |
|---|---|---|---|
| sprite | Phaser.GameObjects.Sprite | No | The Sprite whose animation state will be configured. |
| config | object | No | The 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:
| name | type | optional | default | description |
|---|---|---|---|---|
| src | Phaser.GameObjects.GameObject | No | The Game Object to calculate the transform matrix for. | |
| camera | Phaser.Cameras.Scene2D.Camera | No | The camera being used to render the Game Object. | |
| parentMatrix | Phaser.GameObjects.Components.TransformMatrix | Yes | The transform matrix of the parent container, if any. | |
| ignoreCameraPosition | boolean | Yes | false | Should 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:
| name | type | optional | description |
|---|---|---|---|
| text | Phaser.GameObjects.Text | No | The Text object to calculate the size from. |
| size | Phaser.Types.GameObjects.Text.TextMetrics | No | The Text metrics to use when calculating the size. |
| lines | Array.<string> | No | The 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:
| name | type | optional | description |
|---|---|---|---|
| textStyle | Phaser.GameObjects.TextStyle | No | The 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
Phaser.GameObjects.GameObjectCreator
register
<static> register(factoryType, factoryFunction)
Description:
Registers a Game Object creator function on the GameObjectCreator prototype, making it available for creating Game Objects via the Scene's make property.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| factoryType | string | No | The key of the factory that you will use to call the Phaser.Scene.make[ factoryType ] method. |
| factoryFunction | function | No | The constructor function to be called when you invoke the Phaser.Scene.make method. |
Source: src/gameobjects/GameObjectCreator.js#L154
Since: 3.0.0
remove
<static> remove(factoryType)
Description:
Removes a previously registered custom Game Object Creator from the GameObjectCreator prototype, making it no longer available via the Scene's make property.
With this method you can remove a custom Game Object Creator that has been previously registered in the Game Object Creator. Pass in its factoryType in order to remove it.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| factoryType | string | No | The key of the factory that you want to remove from the GameObjectCreator. |
Source: src/gameobjects/GameObjectCreator.js#L173
Since: 3.0.0
Phaser.GameObjects.RetroFont
Parse
<static> Parse(scene, config)
Description:
Parses a Retro Font configuration object and builds a BitmapFontData structure that can be passed to the BitmapText constructor to render text using a fixed-width retro font.
A retro font is a texture containing a uniform grid of characters, each cell being the same width and height. This function reads the configuration, looks up the source texture frame, then iterates over every character defined in config.chars, calculating its pixel position and normalised UV coordinates within the texture. The resulting data object maps each character code to its own glyph entry and is suitable for registering in the Bitmap Font cache.
If config.chars is an empty string the function returns undefined without producing any data.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| scene | Phaser.Scene | No | A reference to the Phaser Scene. |
| config | Phaser.Types.GameObjects.BitmapText.RetroFontConfig | No | The font configuration object. |
Returns: Phaser.Types.GameObjects.BitmapText.BitmapFontData - A parsed Bitmap Font data entry containing per-character glyph data and UV coordinates, ready for the Bitmap Font cache.
Source: src/gameobjects/bitmaptext/ParseRetroFont.js#L9
Since: 3.0.0
Phaser.GameObjects.BitmapText
ParseFromAtlas
<static> ParseFromAtlas(scene, fontName, textureKey, frameKey, xmlKey, [xSpacing], [ySpacing])
Description:
Parse an XML Bitmap Font from an Atlas.
Adds the parsed Bitmap Font data to the cache with the fontName key.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| scene | Phaser.Scene | No | The Scene to parse the Bitmap Font for. |
| fontName | string | No | The key of the font to add to the Bitmap Font cache. |
| textureKey | string | No | The key of the BitmapFont's texture. |
| frameKey | string | No | The key of the BitmapFont texture's frame. |
| xmlKey | string | No | The key of the XML data of the font to parse. |
| xSpacing | number | Yes | The x-axis spacing to add between each letter. |
| ySpacing | number | Yes | The y-axis spacing to add to the line height. |
Returns: boolean - Whether the parsing was successful or not.
Source: src/gameobjects/bitmaptext/static/BitmapText.js#L1203
Since: 3.0.0
ParseXMLBitmapFont
<static> ParseXMLBitmapFont(xml, frame, [xSpacing], [ySpacing])
Description:
Parse an XML font to Bitmap Font data for the Bitmap Font cache.
Parameters:
| name | type | optional | default | description |
|---|---|---|---|---|
| xml | XMLDocument | No | The XML Document to parse the font from. | |
| frame | Phaser.Textures.Frame | No | The texture frame to take into account when creating the uv data. | |
| xSpacing | number | Yes | 0 | The x-axis spacing to add between each letter. |
| ySpacing | number | Yes | 0 | The y-axis spacing to add to the line height. |
Returns: Phaser.Types.GameObjects.BitmapText.BitmapFontData - The parsed Bitmap Font data.
Source: src/gameobjects/bitmaptext/static/BitmapText.js#L1223
Since: 3.17.0
Phaser.GameObjects.Components
ToJSON
<static> ToJSON(gameObject)
Description:
Build a JSON representation of the given Game Object.
This is typically extended further by Game Object specific implementations.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| gameObject | Phaser.GameObjects.GameObject | No | The Game Object to export as JSON. |
Returns: Phaser.Types.GameObjects.JSONGameObject - A JSON representation of the Game Object.
Source: src/gameobjects/components/ToJSON.js#L7
Since: 3.0.0