SFML community forums

Help => Graphics => Topic started by: nitram_cero on May 04, 2009, 11:31:29 pm

Title: FlipX/Y does not flip using the center as pivot.
Post by: nitram_cero on May 04, 2009, 11:31:29 pm
FlipX/Y does not flip using the center as pivot.
Is this the intention?

If I have an already centered image, and apply a flipX(true), the flip
gets done in respect to the left border.

And now the center is outside the image (left where it was).

I think I've already asked this, but I don't seem to find it in the forums.

Thanks.
-Martín
Title: Re: FlipX/Y does not flip using the center as pivot.
Post by: Nexus on May 04, 2009, 11:37:22 pm
Quote from: "nitram_cero"
FlipX/Y does not flip using the center as pivot.
Is this the intention?
Yes. Flipping X just means the sprite is mirrored so that the left edge becomes the right one and vice versa (analogous to Top/Bottom).
Title: FlipX/Y does not flip using the center as pivot.
Post by: nitram_cero on May 04, 2009, 11:40:02 pm
Thanks, but I don't seem to find a way to center it.

I try this fixup
Code: [Select]

spr_.SetImage(*anim_->frames[keyframe_].image);
spr_.SetCenter((float)spr_.GetImage()->GetWidth()/2, (float)spr_.GetImage()->GetHeight());

//...

spr_.flipX(facing_==Animation::FaceLeft);
if(facing_==Animation::FaceLeft && spr_.GetCenter().x>0 || facing_==Animation::FaceRight && spr_.GetCenter().x<0)
spr_.SetCenter(-spr_.GetCenter().x, spr_.GetCenter().y);


But doesn't work when going left.

(http://i44.tinypic.com/2z4hlzk.png)
(Don't mind the crappy graphics)

Any help?
Thanks!

EDIT:
I forgot that SetImage only changes the sprite size the first time.


Code: [Select]

spr_.SetSubRect(IntRect(0, 0, spr_.GetImage()->GetWidth(), spr_.GetImage()->GetHeight()));

In case anyone was wondering, this fixed my problem.

BTW: No fixup was needed, flipX was working as expected. Sorry! :oops:

Regards
-Martín