Skip to content

Commit 7302ad1

Browse files
committed
StaticTilemapLayerWebGLRenderer: apply rotation and parent transform
1 parent 000beb2 commit 7302ad1

1 file changed

Lines changed: 39 additions & 4 deletions

File tree

src/tilemaps/staticlayer/StaticTilemapLayerWebGLRenderer.js

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020
* @param {Phaser.Tilemaps.StaticTilemapLayer} src - The Game Object being rendered in this call.
2121
* @param {number} interpolationPercentage - Reserved for future use and custom pipelines.
2222
* @param {Phaser.Cameras.Scene2D.Camera} camera - The Camera that is rendering the Game Object.
23+
* @param {Phaser.GameObjects.Components.TransformMatrix} parentMatrix - This transform matrix is defined if the game object is nested
2324
*/
24-
var StaticTilemapLayerWebGLRenderer = function (renderer, src, interpolationPercentage, camera)
25+
var StaticTilemapLayerWebGLRenderer = function (renderer, src, interpolationPercentage, camera, parentMatrix)
2526
{
2627
var tilesets = src.tileset;
2728

@@ -30,9 +31,43 @@ var StaticTilemapLayerWebGLRenderer = function (renderer, src, interpolationPerc
3031

3132
renderer.setPipeline(pipeline);
3233

33-
pipeline.modelIdentity();
34-
pipeline.modelTranslate(src.x - (camera.scrollX * src.scrollFactorX), src.y - (camera.scrollY * src.scrollFactorY), 0);
35-
pipeline.modelScale(src.scaleX, src.scaleY, 1);
34+
var camMatrix = renderer._tempMatrix1;
35+
var layerMatrix = renderer._tempMatrix2;
36+
var calcMatrix = renderer._tempMatrix3;
37+
38+
layerMatrix.applyITRS(src.x, src.y, src.rotation, src.scaleX, src.scaleY);
39+
40+
camMatrix.copyFrom(camera.matrix);
41+
42+
if (parentMatrix)
43+
{
44+
// Multiply the camera by the parent matrix
45+
camMatrix.multiplyWithOffset(parentMatrix, -camera.scrollX * src.scrollFactorX, -camera.scrollY * src.scrollFactorY);
46+
47+
// Undo the camera scroll
48+
layerMatrix.e = src.x;
49+
layerMatrix.f = src.y;
50+
51+
// Multiply by the layer matrix, store result in calcMatrix
52+
camMatrix.multiply(layerMatrix, calcMatrix);
53+
}
54+
else
55+
{
56+
layerMatrix.e -= camera.scrollX * src.scrollFactorX;
57+
layerMatrix.f -= camera.scrollY * src.scrollFactorY;
58+
59+
// Multiply by the layer matrix, store result in calcMatrix
60+
camMatrix.multiply(layerMatrix, calcMatrix);
61+
}
62+
63+
var modelMatrix = pipeline.modelIdentity().modelMatrix;
64+
modelMatrix[0] = calcMatrix.a;
65+
modelMatrix[1] = calcMatrix.b;
66+
modelMatrix[4] = calcMatrix.c;
67+
modelMatrix[5] = calcMatrix.d;
68+
modelMatrix[12] = calcMatrix.e;
69+
modelMatrix[13] = calcMatrix.f;
70+
3671
pipeline.viewLoad2D(camera.matrix.matrix);
3772

3873
for (var i = 0; i < tilesets.length; i++)

0 commit comments

Comments
 (0)