Skip to content

Commit 799efa3

Browse files
committed
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.
1 parent e6aa9f8 commit 799efa3

3 files changed

Lines changed: 25 additions & 1 deletion

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@ If you are an exceptional JavaScript developer and would like to join the Phaser
269269

270270
### New Features
271271

272+
* 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.
273+
272274
### Updates
273275

274276
* TypeScript definitions fixes and updates (thanks @clark-stevenson)

src/Phaser.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,13 @@ var Phaser = Phaser || {
290290
*/
291291
VIDEO: 28,
292292

293+
/**
294+
* Game Object type.
295+
* @constant
296+
* @type {integer}
297+
*/
298+
PENDING_ATLAS: -1,
299+
293300
/**
294301
* Various blend modes supported by Pixi.
295302
*

src/gameobjects/components/LoadTexture.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,29 @@ Phaser.Component.LoadTexture.prototype = {
3434
*
3535
* 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.
3636
*
37+
* You can use the new const `Phaser.PENDING_ATLAS` as the texture key for any sprite.
38+
* Doing this then sets the key to be the `frame` argument (the frame is set to zero).
39+
*
40+
* This allows you to create sprites using `load.image` during development, and then change them
41+
* to use a Texture Atlas later in development by simply searching your code for 'PENDING_ATLAS'
42+
* and swapping it to be the key of the atlas data.
43+
*
3744
* @method
3845
* @param {string|Phaser.RenderTexture|Phaser.BitmapData|Phaser.Video|PIXI.Texture} key - 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.
3946
* @param {string|number} [frame] - 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.
4047
* @param {boolean} [stopAnimation=true] - If an animation is already playing on this Sprite you can choose to stop it or let it carry on playing.
4148
*/
4249
loadTexture: function (key, frame, stopAnimation) {
4350

44-
frame = frame || 0;
51+
if (key === Phaser.PENDING_ATLAS)
52+
{
53+
key = frame;
54+
frame = 0;
55+
}
56+
else
57+
{
58+
frame = frame || 0;
59+
}
4560

4661
if ((stopAnimation || stopAnimation === undefined) && this.animations)
4762
{

0 commit comments

Comments
 (0)