Skip to content

Commit 5106b2c

Browse files
committed
Animations with custom pivots, like those created in Texture Packer with the pivot option enabled, would be mis-aligned if flipped. They now render in the correct position, regardless of scale or flip on either axis. Fix phaserjs#4155
1 parent e8a4d56 commit 5106b2c

3 files changed

Lines changed: 20 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
* Destroying a Scene in HEADLESS mode would throw an error as it tried to access the gl renderer in the Camera class. Fix #4467 (thanks @AndreaBoeAbrahamsen @samme)
8080
* `Tilemap.createFromObjects` would ignore the `scene` argument passed in to the method. It's now used (thanks @samme)
8181
* Fixed a bug in the WebGL and Canvas Renderers where a Sprite with a `flipX` or `flipY` value set would render the offset frames slightly out of place, causing the animation to appear jittery. Also, the sprite would be out of place by its origin. Fix #4636 #3813 (thanks @jronn @B3L7)
82+
* Animations with custom pivots, like those created in Texture Packer with the pivot option enabled, would be mis-aligned if flipped. They now render in the correct position, regardless of scale or flip on either axis. Fix #4155 (thanks @Zax37)
8283

8384
### Examples, Documentation and TypeScript
8485

src/renderer/canvas/CanvasRenderer.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,8 @@ var CanvasRenderer = new Class({
657657
var frameY = cd.y;
658658
var frameWidth = frame.cutWidth;
659659
var frameHeight = frame.cutHeight;
660+
var customPivot = frame.customPivot;
661+
660662
var res = frame.source.resolution;
661663

662664
var displayOriginX = sprite.displayOriginX;
@@ -713,15 +715,21 @@ var CanvasRenderer = new Class({
713715

714716
if (sprite.flipX)
715717
{
716-
x += (-frame.realWidth + (displayOriginX * 2));
718+
if (!customPivot)
719+
{
720+
x += (-frame.realWidth + (displayOriginX * 2));
721+
}
717722

718723
flipX = -1;
719724
}
720725

721726
// Auto-invert the flipY if this is coming from a GLTexture
722727
if (sprite.flipY)
723728
{
724-
y += (-frame.realHeight + (displayOriginY * 2));
729+
if (!customPivot)
730+
{
731+
y += (-frame.realHeight + (displayOriginY * 2));
732+
}
725733

726734
flipY = -1;
727735
}

src/renderer/webgl/pipelines/TextureTintPipeline.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,7 @@ var TextureTintPipeline = new Class({
533533
var frameY = frame.y;
534534
var frameWidth = frame.cutWidth;
535535
var frameHeight = frame.cutHeight;
536+
var customPivot = frame.customPivot;
536537

537538
var displayOriginX = sprite.displayOriginX;
538539
var displayOriginY = sprite.displayOriginY;
@@ -569,15 +570,21 @@ var TextureTintPipeline = new Class({
569570

570571
if (sprite.flipX)
571572
{
572-
x += (-frame.realWidth + (displayOriginX * 2));
573+
if (!customPivot)
574+
{
575+
x += (-frame.realWidth + (displayOriginX * 2));
576+
}
573577

574578
flipX = -1;
575579
}
576580

577581
// Auto-invert the flipY if this is coming from a GLTexture
578582
if (sprite.flipY || (frame.source.isGLTexture && !texture.flipY))
579583
{
580-
y += (-frame.realHeight + (displayOriginY * 2));
584+
if (!customPivot)
585+
{
586+
y += (-frame.realHeight + (displayOriginY * 2));
587+
}
581588

582589
flipY = -1;
583590
}

0 commit comments

Comments
 (0)