new LoadTexture()
The LoadTexture component manages the loading of a texture into the Game Object and the changing of frames.
- Source - gameobjects/components/LoadTexture.js, line 12
Members
-
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
. -
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
.
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
orframeName
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 | 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 entry, or an instance of a RenderTexture, BitmapData 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 - gameobjects/components/LoadTexture.js, line 36
-
resetFrame()
-
Resets the texture frame dimensions that the Game Object uses for rendering.
-
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.