Phaser.Component. LoadTexture

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.

Source - gameobjects/components/LoadTexture.js, line 254

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 - gameobjects/components/LoadTexture.js, line 279

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.

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 - gameobjects/components/LoadTexture.js, line 51

resetFrame()

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

Source - gameobjects/components/LoadTexture.js, line 232

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 - gameobjects/components/LoadTexture.js, line 220

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 - gameobjects/components/LoadTexture.js, line 155
Phaser Copyright © 2012-2016 Photon Storm Ltd.
Documentation generated by JSDoc 3.3.2 on Thu May 19 2016 12:35:39 GMT+0100 (GMT Daylight Time) using the DocStrap template.