Skip to main content
Version: Phaser v4.0.0

Phaser.Textures.Parsers

AtlasXML

<static> AtlasXML(texture, sourceIndex, xml)

Description:

Parses an XML Texture Atlas object and adds all the Frames into a Texture.

Access: private

Parameters:

nametypeoptionaldescription
texturePhaser.Textures.TextureNoThe Texture to add the Frames to.
sourceIndexnumberNoThe index of the TextureSource.
xml*NoThe XML data.

Returns: Phaser.Textures.Texture - The Texture modified by this parser.

Source: src/textures/parsers/AtlasXML.js#L7
Since: 3.7.0

Canvas

<static> Canvas(texture, sourceIndex)

Description:

Adds a Canvas Element to a Texture.

Access: private

Parameters:

nametypeoptionaldescription
texturePhaser.Textures.TextureNoThe Texture to add the Frames to.
sourceIndexnumberNoThe index of the TextureSource.

Returns: Phaser.Textures.Texture - The Texture modified by this parser.

Source: src/textures/parsers/Canvas.js#L7
Since: 3.0.0

Image

<static> Image(texture, sourceIndex)

Description:

Adds an Image Element to a Texture.

Access: private

Parameters:

nametypeoptionaldescription
texturePhaser.Textures.TextureNoThe Texture to add the Frames to.
sourceIndexnumberNoThe index of the TextureSource.

Returns: Phaser.Textures.Texture - The Texture modified by this parser.

Source: src/textures/parsers/Image.js#L7
Since: 3.0.0

JSONArray

<static> JSONArray(texture, sourceIndex, json)

Description:

Parses a Texture Atlas JSON Array and adds the Frames to the Texture. JSON format expected to match that defined by Texture Packer, with the frames property containing an array of Frames.

Access: private

Parameters:

nametypeoptionaldescription
texturePhaser.Textures.TextureNoThe Texture to add the Frames to.
sourceIndexnumberNoThe index of the TextureSource.
jsonobjectNoThe JSON data.

Returns: Phaser.Textures.Texture - The Texture modified by this parser.

Source: src/textures/parsers/JSONArray.js#L9
Since: 3.0.0

JSONHash

<static> JSONHash(texture, sourceIndex, json)

Description:

Parses a Texture Atlas JSON Hash and adds the Frames to the Texture. JSON format expected to match that defined by Texture Packer, with the frames property containing an object of Frames.

Access: private

Parameters:

nametypeoptionaldescription
texturePhaser.Textures.TextureNoThe Texture to add the Frames to.
sourceIndexnumberNoThe index of the TextureSource.
jsonobjectNoThe JSON data.

Returns: Phaser.Textures.Texture - The Texture modified by this parser.

Source: src/textures/parsers/JSONHash.js#L9
Since: 3.0.0

KTXParser

<static> KTXParser(data)

Description:

Parses a KTX (Khronos Texture) format Compressed Texture file and extracts the texture data required to upload it to WebGL. KTX is a container format for GPU-compressed textures that supports formats such as ETC, ASTC, S3TC, and PVRTC.

The parser validates the 12-byte KTX file identifier, confirms the texture uses a compressed format (uncompressed KTX files are not supported), then reads the image dimensions, internal GL format, and all available mipmap levels from the binary data.

Parameters:

nametypeoptionaldescription
dataArrayBufferNoThe raw binary ArrayBuffer of the KTX file, as loaded by the Compressed Texture File Loader.

Returns: Phaser.Types.Textures.CompressedTextureData - A CompressedTextureData object containing the mipmap levels, dimensions, and internal GL format, ready for WebGL upload.

Source: src/textures/parsers/KTXParser.js#L7
Since: 3.60.0

PCT

<static> PCT(texture, decoded)

Description:

Parses a Phaser Compact Texture Atlas (PCT) data object and adds the Frames to the Texture.

The decoded argument is the object produced by Phaser.Textures.Parsers.PCTDecode (or an equivalent, pre-decoded structure). It must contain pages, folders, and frames fields. Frames are mapped to the Texture's source images using the page index on each frame, which corresponds to the index of the matching TextureSource on the Texture.

The page and folder metadata from the decoded data is also copied onto the Texture's customData under the pct key, so it can be inspected at runtime.

This parser is called by Phaser.Textures.TextureManager#addAtlasPCT and is not typically invoked directly.

Access: private

Parameters:

nametypeoptionaldescription
texturePhaser.Textures.TextureNoThe Texture to add the Frames to.
decodedobjectNoThe decoded PCT data, as produced by Phaser.Textures.Parsers.PCTDecode.

Returns: Phaser.Textures.Texture - The Texture modified by this parser.

Source: src/textures/parsers/PCT.js#L7
Since: 4.0.0

PCTDecode

<static> PCTDecode(text)

Description:

Decodes a Phaser Compact Texture Atlas (PCT) file from its raw text representation into a structured object.

This is a standalone helper used by both the PCT atlas loader and the PCT texture parser. It converts the line-oriented PCT text format into an object containing a pages array (one entry per atlas page), a folders dictionary, and a frames map with fully-resolved frame names and positions. Frame page indices map directly to the pages array.

The function validates the version header and rejects files with an unsupported major version or a missing PCT: header, returning null in those cases after logging a warning. Unknown line prefixes introduced in future minor versions are silently skipped, as required by the specification.

See the Phaser Compact Texture Atlas Format Specification document for a full description of the format and the semantics of the returned object.

Parameters:

nametypeoptionaldescription
textstringNoThe raw text contents of a .pct file.

Returns: Object - The decoded PCT structure, or null if the input is invalid.

Source: src/textures/parsers/PCTDecode.js#L129
Since: 4.0.0

PVRParser

<static> PVRParser(data)

Description:

Parses a PVR format Compressed Texture file and generates texture data suitable for WebGL from it.

Parameters:

nametypeoptionaldescription
dataArrayBufferNoThe raw binary ArrayBuffer of the PVR file, as provided by the Compressed Texture File Loader.

Returns: Phaser.Types.Textures.CompressedTextureData - A parsed compressed texture data object containing the mipmap levels, base dimensions, WebGL internal format, and flags indicating it is compressed and does not require mipmap generation.

Source: src/textures/parsers/PVRParser.js#L236
Since: 3.60.0

SpriteSheet

<static> SpriteSheet(texture, sourceIndex, x, y, width, height, config, config.frameWidth, [config.frameHeight], [config.startFrame], [config.endFrame], [config.margin], [config.spacing])

Description:

Parses a Sprite Sheet and adds the Frames to the Texture.

In Phaser terminology a Sprite Sheet is a texture containing different frames, but each frame is the exact same size and cannot be trimmed or rotated.

Access: private

Parameters:

nametypeoptionaldefaultdescription
texturePhaser.Textures.TextureNoThe Texture to add the Frames to.
sourceIndexnumberNoThe index of the TextureSource.
xnumberNoThe top-left coordinate of the Sprite Sheet. Defaults to zero. Used when extracting sheets from atlases.
ynumberNoThe top-left coordinate of the Sprite Sheet. Defaults to zero. Used when extracting sheets from atlases.
widthnumberNoThe width of the source image.
heightnumberNoThe height of the source image.
configobjectNoAn object describing how to parse the Sprite Sheet.
config.frameWidthnumberNoWidth in pixels of a single frame in the sprite sheet.
config.frameHeightnumberYesHeight in pixels of a single frame in the sprite sheet. Defaults to frameWidth if not provided.
config.startFramenumberYes0The frame to start extracting from. Defaults to zero.
config.endFramenumberYes-1The frame to finish extracting at. Defaults to -1, which means 'all frames'.
config.marginnumberYes0If the frames have been drawn with a margin, specify the amount here.
config.spacingnumberYes0If the frames have been drawn with spacing between them, specify the amount here.

Returns: Phaser.Textures.Texture - The Texture modified by this parser.

Source: src/textures/parsers/SpriteSheet.js#L9
Since: 3.0.0

SpriteSheetFromAtlas

<static> SpriteSheetFromAtlas(texture, frame, config, config.frameWidth, [config.frameHeight], [config.startFrame], [config.endFrame], [config.margin], [config.spacing])

Description:

Parses a Sprite Sheet and adds the Frames to the Texture, where the Sprite Sheet is stored as a frame within an Atlas.

In Phaser terminology a Sprite Sheet is a texture containing different frames, but each frame is the exact same size and cannot be trimmed or rotated.

Access: private

Parameters:

nametypeoptionaldefaultdescription
texturePhaser.Textures.TextureNoThe Texture to add the Frames to.
framePhaser.Textures.FrameNoThe Frame that contains the Sprite Sheet.
configobjectNoAn object describing how to parse the Sprite Sheet.
config.frameWidthnumberNoWidth in pixels of a single frame in the sprite sheet.
config.frameHeightnumberYesHeight in pixels of a single frame in the sprite sheet. Defaults to frameWidth if not provided.
config.startFramenumberYes0Index of the start frame in the sprite sheet
config.endFramenumberYes-1Index of the end frame in the sprite sheet. -1 means all the rest of the frames
config.marginnumberYes0If the frames have been drawn with a margin, specify the amount here.
config.spacingnumberYes0If the frames have been drawn with spacing between them, specify the amount here.

Returns: Phaser.Textures.Texture - The Texture modified by this parser.

Source: src/textures/parsers/SpriteSheetFromAtlas.js#L9
Since: 3.0.0

UnityYAML

<static> UnityYAML(texture, sourceIndex, yaml)

Description:

Parses a Unity YAML File and creates Frames in the Texture. For more details about Sprite Meta Data see https://docs.unity3d.com/ScriptReference/SpriteMetaData.html

Access: private

Parameters:

nametypeoptionaldescription
texturePhaser.Textures.TextureNoThe Texture to add the Frames to.
sourceIndexnumberNoThe index of the TextureSource.
yamlobjectNoThe YAML data.

Returns: Phaser.Textures.Texture - The Texture modified by this parser.

Source: src/textures/parsers/UnityYAML.js#L38
Since: 3.0.0

verifyCompressedTexture

<static> verifyCompressedTexture(data)

Description:

Verify whether the given compressed texture data is valid.

Compare the dimensions of each mip layer to the rules for that specific format.

Mip layer size is assumed to have been calculated correctly during parsing.

Parameters:

nametypeoptionaldescription
dataPhaser.Types.Textures.CompressedTextureDataNoThe compressed texture data to verify.

Returns: boolean - Whether the compressed texture data is valid.

Source: src/textures/parsers/VerifyCompressedTexture.js#L9
Since: 3.80.0