I’ve been working on implementing texture packer support for our game. We have setup the loaders no problem, and sprites are mostly rendering correctly. But I’m having real trouble understanding how to handle a frame that is both rotated and trimmed.
These assets are from a power bar, so the idea is the artist has set them up with trim such that when they are all placed in the same position in game they should line up neatly as segments of the bar. However as can be seen in this screenshot, some segments appear almost rotated 180 upside down, and all these sprites are ones rotated by texture packer. The red square is the origin they should all share.
(just to explain texture packer has a rotation and trim feature that optimises the sprite sheet size, so this is done before loading into monogame, so unrelated to the sprites rotation in game).
And the render sprite code. Trim will either have some value or be zero in case of untrimmed.
Rectangle frame = sprite.TextureRegion.Frame;
Rectangle sourceRect = sprite.TextureRegion.SourceRectangle;
Rectangle trim = sprite.TextureRegion.Trim;
Vector2 size = sprite.TextureRegion.Size;
Vector2 origin = new Vector2(size.X * sprite.Anchor.X - trim.X, size.Y * sprite.Anchor.Y - trim.Y);
sprite.WorldMatrix.Decompose(out Vector2 scale, out float rotation, out Vector2 translation);
if (sprite.TextureRegion.IsRotated)
{
frame = new Rectangle(frame.X, frame.Y, frame.Height, frame.Width);
rotation -= ClockwiseNinetyDegreeRotation;
origin = new Vector2(size.X * (1 - sprite.Anchor.Y) - trim.Y, size.Y * sprite.Anchor.X - trim.X);
}
batcher.DrawSprite(
sprite.TextureRegion.BaseTexture,
translation,
frame,
sprite.Tint * sprite.WorldAlpha,
rotation,
origin,
scale,
sprite.Effect,
0
);
Does anyone have any knowledge here? Googling is not proving very fruitful, other people have implemented it but good info on how seems none existent. Currently I am just digging in other frameworks source code and attempting to understand their methods.