character: GetCharacterTransform: Set pivot point before flipping

BREAKING CHANGE. This way the pivot point stays in the same position
regardless of flips.
This commit is contained in:
Sebastian Krzyszkowiak 2022-07-14 00:25:44 +02:00
parent ffdebba9ec
commit ac83b72899
No known key found for this signature in database
GPG key ID: E8F235CF3BDBC3FF

View file

@ -738,16 +738,12 @@ SYMBOL_EXPORT ALLEGRO_TRANSFORM GetCharacterTransform(struct Game* game, struct
int w = character->spritesheet->width, h = character->spritesheet->height;
al_identity_transform(&transform);
al_translate_transform(&transform, -w / 2.0, -h / 2.0);
al_scale_transform(&transform, ((character->flipX ^ character->spritesheet->flipX ^ character->frame->flipX) ? -1 : 1), ((character->flipY ^ character->spritesheet->flipY ^ character->frame->flipY) ? -1 : 1)); // flipping; FIXME: should it be here or later?
al_translate_transform(&transform, w / 2.0, h / 2.0);
al_translate_transform(&transform, -w * character->spritesheet->pivotX, -h * character->spritesheet->pivotY); // pivot
al_translate_transform(&transform, -w * character->spritesheet->pivotX, -h * character->spritesheet->pivotY);
al_scale_transform(&transform, ((character->flipX ^ character->spritesheet->flipX ^ character->frame->flipX) ? -1 : 1), ((character->flipY ^ character->spritesheet->flipY ^ character->frame->flipY) ? -1 : 1));
al_scale_transform(&transform, character->scaleX, character->scaleY);
al_rotate_transform(&transform, character->angle);
al_translate_transform(&transform, character->spritesheet->offsetX, character->spritesheet->offsetY); // spritesheet offset
al_translate_transform(&transform, GetCharacterX(game, character), GetCharacterY(game, character)); // position
al_translate_transform(&transform, character->spritesheet->offsetX, character->spritesheet->offsetY);
al_translate_transform(&transform, GetCharacterX(game, character), GetCharacterY(game, character));
if (character->parent) {
ALLEGRO_TRANSFORM parent = GetCharacterTransform(game, character->parent);