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

Author Topic: How to flip sprite horizontal?  (Read 5371 times)

0 Members and 1 Guest are viewing this topic.

Chunker120

  • Newbie
  • *
  • Posts: 31
    • View Profile
How to flip sprite horizontal?
« on: May 12, 2013, 04:44:07 pm »
I have an animation in a top-down perspective, but I want the sprite to get flipped horizontal if the player faces east. The sprite class doesn't by default have any methods that would help me achieve that, so how would I go around flipping a sprite horizontally?

Grimshaw

  • Hero Member
  • *****
  • Posts: 631
  • Nephilim SDK
    • View Profile
Re: How to flip sprite horizontal?
« Reply #1 on: May 12, 2013, 05:05:24 pm »
sprite.scale(-1,1);

:)

lrx

  • Newbie
  • *
  • Posts: 29
    • View Profile
Re: How to flip sprite horizontal?
« Reply #2 on: May 12, 2013, 05:05:52 pm »
probably rotating sprite would be easiest

edit: nvm scaling is even easier then rotating :P

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: How to flip sprite horizontal?
« Reply #3 on: May 12, 2013, 05:13:59 pm »
edit: nvm scaling is even easier then rotating :P
The operations are not equivalent. Rotating by 180° won't give you the mirror image (the sprite looks upside down). The alternative to scaling is to set the texture rect using a negative width.

By the way, this has been asked many times, please use the forum search before posting.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development: