Skip to content

Commit 3888653

Browse files
committed
Added new loadTexture and setFrame calls. Will test crop support.
1 parent c0b34ed commit 3888653

1 file changed

Lines changed: 47 additions & 31 deletions

File tree

src/gameobjects/TileSprite.js

Lines changed: 47 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,6 @@ Phaser.TileSprite = function (game, x, y, width, height, key, frame) {
8484

8585
PIXI.TilingSprite.call(this, PIXI.TextureCache['__default'], width, height);
8686

87-
this.loadTexture(key, frame);
88-
8987
this.position.set(x, y);
9088

9189
/**
@@ -151,6 +149,8 @@ Phaser.TileSprite = function (game, x, y, width, height, key, frame) {
151149
*/
152150
this._cache = [ 0, 0, 0, 0, 1, 0, 1, 0, 0 ];
153151

152+
this.loadTexture(key, frame);
153+
154154
};
155155

156156
Phaser.TileSprite.prototype = Object.create(PIXI.TilingSprite.prototype);
@@ -327,72 +327,88 @@ Phaser.TileSprite.prototype.stopScroll = function() {
327327
*
328328
* @method Phaser.TileSprite#loadTexture
329329
* @memberof Phaser.TileSprite
330-
* @param {string|Phaser.RenderTexture|Phaser.BitmapData|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 entry, or an instance of a RenderTexture, BitmapData or PIXI.Texture.
331-
* @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.
330+
* @param {string|Phaser.RenderTexture|Phaser.BitmapData|PIXI.Texture} key - This is the image or texture used by the TileSprite 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.
331+
* @param {string|number} frame - If this TileSprite 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.
332332
*/
333333
Phaser.TileSprite.prototype.loadTexture = function (key, frame) {
334334

335335
frame = frame || 0;
336+
337+
this.key = key;
336338

337339
if (key instanceof Phaser.RenderTexture)
338340
{
339341
this.key = key.key;
340342
this.setTexture(key);
341-
return;
342343
}
343344
else if (key instanceof Phaser.BitmapData)
344345
{
345-
this.key = key;
346346
this.setTexture(key.texture);
347-
return;
348347
}
349348
else if (key instanceof PIXI.Texture)
350349
{
351-
this.key = key;
352350
this.setTexture(key);
353-
return;
354351
}
355352
else
356353
{
357354
if (key === null || typeof key === 'undefined')
358355
{
359356
this.key = '__default';
360357
this.setTexture(PIXI.TextureCache[this.key]);
361-
return;
362358
}
363359
else if (typeof key === 'string' && !this.game.cache.checkImageKey(key))
364360
{
365361
this.key = '__missing';
366362
this.setTexture(PIXI.TextureCache[this.key]);
367-
return;
368-
}
369-
370-
if (this.game.cache.isSpriteSheet(key))
371-
{
372-
this.key = key;
373-
374-
// var frameData = this.game.cache.getFrameData(key);
375-
this.animations.loadFrameData(this.game.cache.getFrameData(key));
376-
377-
if (typeof frame === 'string')
378-
{
379-
this.frameName = frame;
380-
}
381-
else
382-
{
383-
this.frame = frame;
384-
}
385363
}
386364
else
387365
{
388-
this.key = key;
389-
this.setTexture(PIXI.TextureCache[key]);
390-
return;
366+
this.setTexture(new PIXI.Texture(PIXI.BaseTextureCache[key]));
367+
this.animations.loadFrameData(this.game.cache.getFrameData(key), frame);
391368
}
392369
}
393370

394371
};
395372

373+
/**
374+
* Sets the Texture frame the TileSprite uses for rendering.
375+
* This is primarily an internal method used by TileSprite.loadTexture, although you may call it directly.
376+
*
377+
* @method Phaser.TileSprite#setFrame
378+
* @memberof Phaser.TileSprite
379+
* @param {Phaser.Frame} frame - The Frame to be used by the TileSprite texture.
380+
*/
381+
Phaser.TileSprite.prototype.setFrame = function(frame) {
382+
383+
// this._cache[9] = frame.x;
384+
// this._cache[10] = frame.y;
385+
// this._cache[11] = frame.width;
386+
// this._cache[12] = frame.height;
387+
// this._cache[13] = frame.spriteSourceSizeX;
388+
// this._cache[14] = frame.spriteSourceSizeY;
389+
390+
this.texture.frame.x = frame.x;
391+
this.texture.frame.y = frame.y;
392+
this.texture.frame.width = frame.width;
393+
this.texture.frame.height = frame.height;
394+
395+
if (frame.trimmed)
396+
{
397+
this.texture.trim = { x: frame.spriteSourceSizeX, y: frame.spriteSourceSizeY, width: frame.width, height: frame.height };
398+
}
399+
400+
if (this.game.renderType === Phaser.WEBGL)
401+
{
402+
PIXI.WebGLRenderer.updateTextureFrame(this.texture);
403+
}
404+
405+
// if (this.cropRect)
406+
// {
407+
// this.updateCrop();
408+
// }
409+
410+
};
411+
396412
/**
397413
* Destroys the TileSprite. This removes it from its parent group, destroys the event and animation handlers if present
398414
* and nulls its reference to game, freeing it up for garbage collection.

0 commit comments

Comments
 (0)