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.
You can use the new const Phaser.PENDING_ATLAS
as the texture key for any sprite.
Doing this then sets the key to be the frame
argument (the frame is set to zero).
This allows you to create sprites using load.image
during development, and then change them
to use a Texture Atlas later in development by simply searching your code for 'PENDING_ATLAS'
and swapping it to be the key of the atlas data.
Note: You cannot use a RenderTexture as a texture for a TileSprite.
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 51)
Please login to continue.