Skip to content

Commit 1b85512

Browse files
committed
Fixed a bug in the canvas rendering of both the Static and Dynamic Tilemap Layers where the camera matrix was being multiplied twice with the layer, causing the scale and placement to be off
1 parent e4c3821 commit 1b85512

3 files changed

Lines changed: 19 additions & 19 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
### Bug Fixes
1515

16+
* Fixed a bug in the canvas rendering of both the Static and Dynamic Tilemap Layers where the camera matrix was being multiplied twice with the layer, causing the scale and placement to be off (thanks galerijanamar)
17+
1618
### Examples and TypeScript
1719

1820
Thanks to the following for helping with the Phaser 3 Examples and TypeScript definitions, either by reporting errors, or even better, fixing them:

src/tilemaps/dynamiclayer/DynamicTilemapLayerCanvasRenderer.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ var DynamicTilemapLayerCanvasRenderer = function (renderer, src, interpolationPe
3939

4040
camMatrix.copyFrom(camera.matrix);
4141

42+
var ctx = renderer.currentContext;
43+
var gidMap = src.gidMap;
44+
45+
ctx.save();
46+
4247
if (parentMatrix)
4348
{
4449
// Multiply the camera by the parent matrix
@@ -50,23 +55,17 @@ var DynamicTilemapLayerCanvasRenderer = function (renderer, src, interpolationPe
5055

5156
// Multiply by the Sprite matrix, store result in calcMatrix
5257
camMatrix.multiply(layerMatrix, calcMatrix);
58+
59+
calcMatrix.copyToContext(ctx);
5360
}
5461
else
5562
{
5663
layerMatrix.e -= camera.scrollX * src.scrollFactorX;
5764
layerMatrix.f -= camera.scrollY * src.scrollFactorY;
5865

59-
// Multiply by the Sprite matrix, store result in calcMatrix
60-
camMatrix.multiply(layerMatrix, calcMatrix);
66+
layerMatrix.copyToContext(ctx);
6167
}
6268

63-
var ctx = renderer.currentContext;
64-
var gidMap = src.gidMap;
65-
66-
ctx.save();
67-
68-
calcMatrix.copyToContext(ctx);
69-
7069
var alpha = camera.alpha * src.alpha;
7170

7271
for (var i = 0; i < tileCount; i++)

src/tilemaps/staticlayer/StaticTilemapLayerCanvasRenderer.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ var StaticTilemapLayerCanvasRenderer = function (renderer, src, interpolationPer
3939

4040
camMatrix.copyFrom(camera.matrix);
4141

42+
var ctx = renderer.currentContext;
43+
var gidMap = src.gidMap;
44+
45+
ctx.save();
46+
4247
if (parentMatrix)
4348
{
4449
// Multiply the camera by the parent matrix
@@ -48,25 +53,19 @@ var StaticTilemapLayerCanvasRenderer = function (renderer, src, interpolationPer
4853
layerMatrix.e = src.x;
4954
layerMatrix.f = src.y;
5055

51-
// Multiply by the Sprite matrix, store result in calcMatrix
5256
camMatrix.multiply(layerMatrix, calcMatrix);
57+
58+
calcMatrix.copyToContext(ctx);
5359
}
5460
else
5561
{
62+
// Undo the camera scroll
5663
layerMatrix.e -= camera.scrollX * src.scrollFactorX;
5764
layerMatrix.f -= camera.scrollY * src.scrollFactorY;
5865

59-
// Multiply by the Sprite matrix, store result in calcMatrix
60-
camMatrix.multiply(layerMatrix, calcMatrix);
66+
layerMatrix.copyToContext(ctx);
6167
}
6268

63-
var ctx = renderer.currentContext;
64-
var gidMap = src.gidMap;
65-
66-
ctx.save();
67-
68-
calcMatrix.copyToContext(ctx);
69-
7069
var alpha = camera.alpha * src.alpha;
7170

7271
ctx.globalAlpha = camera.alpha * src.alpha;

0 commit comments

Comments
 (0)