flixel-addons icon indicating copy to clipboard operation
flixel-addons copied to clipboard

FlxSpine doesn't handle scaling correctly

Open bendmorris opened this issue 9 years ago • 2 comments

It seems that scaling is distorted when an image is rotated. This works correctly with renderMeshes = true, and incorrectly when renderMeshes = false. For example, here's a slime which does a "squishing" animation (where it gets smaller vertically, then goes back to normal.)

Normal slime:

screen shot 2016-08-11 at 10 17 35 am

With renderMeshes (this is also what it looks like in the Spine editor):

screen shot 2016-08-11 at 10 08 18 am

Without renderMeshes, he's getting smaller along the horizontal axis instead:

screen shot 2016-08-11 at 10 07 30 am

For this specific animation, swapping worldScaleX and worldScaleY:

wrapper.scale.x *= worldScaleY * flipX;
wrapper.scale.y *= worldScaleX * flipY;

...gives the right appearance, but doesn't seem like a general solution.

I'm looking into this, but leaving this here in case anyone else has seen the issue or has an idea.

bendmorris avatar Aug 11 '16 17:08 bendmorris

It seems like the problem is that "x" and "y" in scale timelines represent bone-local axes so are being applied incorrectly. In my case the bone is oriented at about 90 degrees, so the scaling at runtime is 90 degrees off.

bendmorris avatar Aug 12 '16 01:08 bendmorris

In case anyone else runs into this, I'm using the following workaround:

    _matrix.rotate(wrapper.angle * Math.PI / 180);
    _matrix.scale(wrapper.scale.x, wrapper.scale.y);
    _matrix.translate(wrapper.origin.x, wrapper.origin.y);
    _matrix.scale(bone.worldScaleX * flipX, bone.worldScaleY * flipY);
    _matrix.rotate(flip * -bone.worldRotation * Math.PI / 180);
    _matrix.translate(
        skeleton.x + bone.worldX,
        skeleton.y + bone.worldY
    );

...then using a very hacky method with @:access to render the wrapper image with this transformation matrix instead of calling draw directly. This isn't quite perfect yet - it's off by 180 degrees if you negatively scale an image which was rotated in the atlas - but good enough for me right now.

bendmorris avatar Aug 13 '16 17:08 bendmorris