😅 OK, so I did some reading/testing and it turns out that my previous post was incorrect for a couple of reasons:
- The property should be
angle (degrees) or rotation (radians). _angle does nothing. (I was thinking of the Game_Picture property, whoops.)
- Rotation actually occurs about the sprite's
pivot (source). This has a similar structure to the anchor. The difference is that:
anchor defines the origin of the sprite's coordinate system, and
pivot defines the point around which it rotates.
Also, anchor is a percentage (0~1) but pivot is measured in sprite coordinates (px).
The default pivot is (0, 0); the rotation axis can be "set" via the anchor like I described, but as you've seen, that is not an ideal approach.
The "jump" you were seeing was the change of anchor.
Sprite_Character uses an anchor of (0.5, 1); the default anchor is (0, 0).
Try something like this instead:
JavaScript:
// set pivot point to centre of sprite
sprite.pivot.x = sprite.width / 2;
sprite.pivot.y = sprite.height / 2;
// rotate sprite to an angle of 45 degrees
sprite.angle = 45;
I.e. only change the sprite's
pivot, not its
anchor.
😮💨
Note that the pivot coordinates are dependent on the size of the sprite, which may be inaccurate if you try to fetch it too early, i.e. before its image is loaded. There are ways to get around this, e.g. reset the pivot every time you change the angle, or attach a suitable load listener to the bitmap.