Navigation
These archived docs are for Phaser 2.4.4 Phaser 3 docs can be found on newdocs.phaser.io.
Phaser CE docs can be found on the Phaser CE Documentation site.

Constructor

Phaser.Component. LoadTexture

new LoadTexture()

The LoadTexture component manages the loading of a texture into the Game Object and the changing of frames.

Source code: gameobjects/components/LoadTexture.js (Line 12)

Public Properties

frame : integer

Gets or sets the current frame index of the texture being used to render this Game Object.

To change the frame set frame to the index of the new frame in the sprite sheet you wish this Game Object to use, for example: player.frame = 4.

If the frame index given doesn't exist it will revert to the first frame found in the texture.

If you are using a texture atlas then you should use the frameName property instead.

If you wish to fully replace the texture being used see loadTexture.

Source code: gameobjects/components/LoadTexture.js (Line 218)

frameName : string

Gets or sets the current frame name of the texture being used to render this Game Object.

To change the frame set frameName to the name of the new frame in the texture atlas you wish this Game Object to use, for example: player.frameName = "idle".

If the frame name given doesn't exist it will revert to the first frame found in the texture and throw a console warning.

If you are using a sprite sheet then you should use the frame property instead.

If you wish to fully replace the texture being used see loadTexture.

Source code: gameobjects/components/LoadTexture.js (Line 243)

Public Methods

loadTexture(key, frame, stopAnimation)

Changes the base texture the Game Object is using. The old texture is removed and the new one is referenced or fetched from the Cache.

If your Game Object is using a frame from a texture atlas and you just wish to change to another frame, then see the frame or frameName properties instead.

You should only use loadTexture if you want to replace the base texture entirely.

Calling this method causes a WebGL texture update, so use sparingly or in low-intensity portions of your game, or if you know the new texture is already on the GPU.

Parameters
Name Type Argument Default Description
key string | Phaser.RenderTexture | Phaser.BitmapData | Phaser.Video | PIXI.Texture

This is the image or texture used by the Sprite during rendering. It can be a string which is a reference to the Cache Image entry, or an instance of a RenderTexture, BitmapData, Video or PIXI.Texture.

frame string | number <optional>

If this Sprite is using part of a sprite sheet or texture atlas you can specify the exact frame to use by giving a string or numeric index.

stopAnimation boolean <optional>
true

If an animation is already playing on this Sprite you can choose to stop it or let it carry on playing.

Source code: gameobjects/components/LoadTexture.js (Line 42)

resetFrame()

Resets the texture frame dimensions that the Game Object uses for rendering.

Source code: gameobjects/components/LoadTexture.js (Line 196)

resizeFrame(parent, width, height)

Resizes the Frame dimensions that the Game Object uses for rendering.

You shouldn't normally need to ever call this, but in the case of special texture types such as Video or BitmapData it can be useful to adjust the dimensions directly in this way.

Parameters
Name Type Description
parent object

The parent texture object that caused the resize, i.e. a Phaser.Video object.

width integer

The new width of the texture.

height integer

The new height of the texture.

Source code: gameobjects/components/LoadTexture.js (Line 184)

setFrame(frame)

Sets the texture frame the Game Object uses for rendering.

This is primarily an internal method used by loadTexture, but is exposed for the use of plugins and custom classes.

Parameters
Name Type Description
frame Phaser.Frame

The Frame to be used by the texture.

Source code: gameobjects/components/LoadTexture.js (Line 119)