Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: FlipX/Y does not flip using the center as pivot.  (Read 2065 times)

0 Members and 1 Guest are viewing this topic.

nitram_cero

  • Full Member
  • ***
  • Posts: 166
    • View Profile
FlipX/Y does not flip using the center as pivot.
« 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

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: FlipX/Y does not flip using the center as pivot.
« Reply #1 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).
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

nitram_cero

  • Full Member
  • ***
  • Posts: 166
    • View Profile
FlipX/Y does not flip using the center as pivot.
« Reply #2 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.


(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