Skip to content

Commit 7144b10

Browse files
committed
TileSprites fixed for WebGL.
1 parent cab0f93 commit 7144b10

3 files changed

Lines changed: 26 additions & 7 deletions

File tree

src/Phaser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*/
1111
var Phaser = Phaser || {
1212

13-
VERSION: '2.4.0-RC2',
13+
VERSION: '2.4.0-RC3',
1414
GAMES: [],
1515

1616
AUTO: 0,

src/gameobjects/TileSprite.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,15 @@
1010
*
1111
* TileSprites have no input handler or physics bodies by default, both need enabling in the same way as for normal Sprites.
1212
*
13+
* You shouldn't ever create a TileSprite any larger than your actual screen size. If you want to create a large repeating background
14+
* that scrolls across the whole map of your game, then you create a TileSprite that fits the screen size and then use the `tilePosition`
15+
* property to scroll the texture as the player moves. If you create a TileSprite that is thousands of pixels in size then it will
16+
* consume huge amounts of memory and cause performance issues. Remember: use `tilePosition` to scroll your texture and `tileScale` to
17+
* adjust the scale of the texture - don't resize the sprite itself or make it larger than it needs.
18+
*
1319
* An important note about texture dimensions:
1420
*
15-
* When running under Canvas a TileSprite can use any texture size without issue. When running under WebGL the texture should be
21+
* When running under Canvas a TileSprite can use any texture size without issue. When running under WebGL the texture should ideally be
1622
* a power of two in size (i.e. 4, 8, 16, 32, 64, 128, 256, 512, etch pixels width by height). If the texture isn't a power of two
1723
* it will be rendered to a blank canvas that is the correct size, which means you may have 'blank' areas appearing to the right and
1824
* bottom of your frame. To avoid this ensure your textures are perfect powers of two.
@@ -77,7 +83,9 @@ Phaser.TileSprite = function (game, x, y, width, height, key, frame) {
7783
*/
7884
this._scroll = new Phaser.Point();
7985

80-
PIXI.TilingSprite.call(this, PIXI.TextureCache['__default'], width, height);
86+
var def = game.cache.getImage('__default', true);
87+
88+
PIXI.TilingSprite.call(this, new PIXI.Texture(def.base), width, height);
8189

8290
Phaser.Component.Core.init.call(this, game, x, y, key, frame);
8391

src/pixi/extras/TilingSprite.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
*/
1515
PIXI.TilingSprite = function(texture, width, height)
1616
{
17-
PIXI.Sprite.call( this, texture);
17+
PIXI.Sprite.call(this, texture);
1818

1919
/**
20-
* The with of the tiling sprite
20+
* The width of the tiling sprite
2121
*
2222
* @property width
2323
* @type Number
@@ -377,6 +377,7 @@ PIXI.TilingSprite.prototype.generateTilingTexture = function(forcePowerOfTwo)
377377
{
378378
this.canvasBuffer = new PIXI.CanvasBuffer(targetWidth, targetHeight);
379379
this.tilingTexture = PIXI.Texture.fromCanvas(this.canvasBuffer.canvas);
380+
this.tilingTexture = PIXI.Texture.fromCanvas(this.canvasBuffer.canvas);
380381
this.tilingTexture.isTiling = true;
381382
this.tilingTexture.needsUpdate = true;
382383
}
@@ -387,15 +388,25 @@ PIXI.TilingSprite.prototype.generateTilingTexture = function(forcePowerOfTwo)
387388
this.canvasBuffer.context.strokeRect(0, 0, targetWidth, targetHeight);
388389
}
389390

391+
// If a sprite sheet we need this:
392+
var w = texture.crop.width;
393+
var h = texture.crop.height;
394+
395+
if (w !== targetWidth || h !== targetHeight)
396+
{
397+
w = targetWidth;
398+
h = targetHeight;
399+
}
400+
390401
this.canvasBuffer.context.drawImage(texture.baseTexture.source,
391402
texture.crop.x,
392403
texture.crop.y,
393404
texture.crop.width,
394405
texture.crop.height,
395406
dx,
396407
dy,
397-
texture.crop.width,
398-
texture.crop.height);
408+
w,
409+
h);
399410

400411
this.tileScaleOffset.x = frame.width / targetWidth;
401412
this.tileScaleOffset.y = frame.height / targetHeight;

0 commit comments

Comments
 (0)