Skip to content

Commit 14399d6

Browse files
committed
TileSprite can now set frame of the pattern texture
1 parent 4a103f9 commit 14399d6

3 files changed

Lines changed: 13 additions & 6 deletions

File tree

src/gameobjects/tilesprite/TileSprite.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ var TileSprite = new Class({
175175
*/
176176
this.canvasBufferCtx = this.canvasBuffer.getContext('2d');
177177

178+
this.oldFrame = null;
179+
178180
this.updateTileTexture();
179181

180182
scene.sys.game.renderer.onContextRestored(function (renderer)
@@ -194,11 +196,14 @@ var TileSprite = new Class({
194196
*/
195197
updateTileTexture: function ()
196198
{
197-
if (!this.dirty)
199+
if (!this.dirty && this.oldFrame == this.frame)
198200
{
199201
return;
200202
}
201203

204+
this.oldFrame = this.frame;
205+
206+
this.canvasBufferCtx.clearRect(0, 0, this.canvasBuffer.width, this.canvasBuffer.height);
202207
this.canvasBufferCtx.drawImage(
203208
this.frame.source.image,
204209
this.frame.cutX, this.frame.cutY,

src/gameobjects/tilesprite/TileSpriteCanvasRenderer.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ var TileSpriteCanvasRenderer = function (renderer, src, interpolationPercentage,
3030
var ctx = renderer.currentContext;
3131
var frame = src.frame;
3232

33+
src.updateTileTexture();
34+
3335
// Blend Mode
3436

3537
if (renderer.currentBlendMode !== src.blendMode)

src/renderer/webgl/WebGLRenderer.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,11 +1494,11 @@ var WebGLRenderer = new Class({
14941494
{
14951495
this.setTexture2D(dstTexture, 0);
14961496

1497-
if (!shouldReallocate)
1498-
{
1499-
gl.texSubImage2D(0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, srcCanvas);
1500-
}
1501-
else
1497+
//if (!shouldReallocate && dstTexture.width >= srcCanvas.width || dstTexture.height >= srcCanvas.height)
1498+
//{
1499+
// gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, srcCanvas.width, srcCanvas.height, gl.RGBA, gl.UNSIGNED_BYTE, srcCanvas);
1500+
//}
1501+
//else
15021502
{
15031503
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, srcCanvas);
15041504
dstTexture.width = srcCanvas.width;

0 commit comments

Comments
 (0)