Skip to content

Commit c94f603

Browse files
committed
Finally rotation handles all edge-cases, including negative x and y scales
1 parent 9f15b5a commit c94f603

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

plugins/spine/src/gameobject/SpineGameObjectWebGLRenderer.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ var SpineGameObjectWebGLRenderer = function (renderer, src, interpolationPercent
5959
var spriteMatrix = renderer._tempMatrix2;
6060
var calcMatrix = renderer._tempMatrix3;
6161

62-
spriteMatrix.applyITRS(src.x, src.y, src.rotation, src.scaleX, src.scaleY);
62+
spriteMatrix.applyITRS(src.x, src.y, src.rotation, Math.abs(src.scaleX), Math.abs(src.scaleY));
6363

6464
camMatrix.copyFrom(camera.matrix);
6565

@@ -92,18 +92,30 @@ var SpineGameObjectWebGLRenderer = function (renderer, src, interpolationPercent
9292
skeleton.scaleX = calcMatrix.scaleX;
9393
skeleton.scaleY = calcMatrix.scaleY;
9494

95-
// +90 degrees to account for the difference in Spine vs. Phaser rotation
96-
src.root.rotation = Wrap(RadToDeg(CounterClockwise(calcMatrix.rotationNormalized)) + 90, 0, 360);
97-
9895
if (src.scaleX < 0)
9996
{
10097
skeleton.scaleX *= -1;
101-
// src.root.rotation = 360 - Wrap(src.root.rotation - (360 - RadToDeg(calcMatrix.rotationNormalized), 0, 360));
98+
99+
src.root.rotation = RadToDeg(calcMatrix.rotationNormalized);
100+
}
101+
else
102+
{
103+
// +90 degrees to account for the difference in Spine vs. Phaser rotation
104+
src.root.rotation = Wrap(RadToDeg(CounterClockwise(calcMatrix.rotationNormalized)) + 90, 0, 360);
102105
}
103106

104107
if (src.scaleY < 0)
105108
{
106109
skeleton.scaleY *= -1;
110+
111+
if (src.scaleX < 0)
112+
{
113+
src.root.rotation -= (RadToDeg(calcMatrix.rotationNormalized) * 2);
114+
}
115+
else
116+
{
117+
src.root.rotation += (RadToDeg(calcMatrix.rotationNormalized) * 2);
118+
}
107119
}
108120

109121
if (camera.renderToTexture)

0 commit comments

Comments
 (0)