Closed GaryStanton closed 4 months ago
To address the issue where a TileSprite does not tile correctly when one dimension is zero, modify the TileSprite
class in TileSprite.js
as follows:
TileSprite
constructor, update the width and height assignment to ensure tiling is applied correctly:if (!width || !height) {
width = width || displayFrame.width;
height = height || displayFrame.height;
} else {
width = Math.floor(width);
height = Math.floor(height);
}
setFrame
method, ensure the canvas dimensions are updated correctly:if (!newFrame.cutWidth || !newFrame.cutHeight) {
this.renderFlags &= ~_FLAG;
} else {
this.renderFlags |= _FLAG;
}
this.displayFrame = newFrame;
this.dirty = true;
this.updateTileTexture();
// Ensure the canvas dimensions are updated
this.canvas.width = this.width || newFrame.width;
this.canvas.height = this.height || newFrame.height;
return this;
These changes ensure that the TileSprite respects the specified dimension and tiles the texture correctly when one dimension is zero.
/src/gameobjects/tilesprite/TileSprite.js /src/gameobjects/tilesprite/TileSpriteFactory.js /src/gameobjects/tilesprite/TileSpriteCreator.js
Hi @GaryStanton. Thanks for submitting this issue. We have fixed this and pushed it to the master
branch. It will be part of the next release. Do test it out and let us know if you encounter any issues.
@zekeatchan this appears to be a regression in 4.0.0-beta.1. You can verify this easily thanks to @GaryStanton 's sandbox MRE.
Version
Description
If you set a tilesprite with a zero width or height, and specify the other dimension - while it does take the dimensions from the texture, as it should, it doesn't tile the sprite to the other dimension.
So for example, if I have a texture that is 100x100px, I would expect the following code to result in a tile sprite that is 100px wide and 500px high, with my texture tiled five times vertically:
this.add.tileSprite(0, 0, 0, 500, 'my100pxTexture')
However, it simply results in a tilesprite of 100x100px, matching the dimensions of the texture.
Example Test Code
https://phaser.io/sandbox/4nryhSBH