0

I am making a game using the Pygame development module. When a user for my game presses the left key, I would like my character to "face" left and when the user presses the right key, I would like my character to be flipped and "face" the right. The character is one I drew and imported in. I am aware of the flip function in Pygame, but I think there will be errors. If the character starts off facing the left, and the user presses the right key, the character will be flipped and will move to the right. However, if he/she lets go of the right key and then presses it again, the character will flip and face the left, but will continue to move to the right. Is there any way to solve this problem? I already know how to move the character; I am having problems with flipping it. Also, another idea I have considered is the diplay blitting one image when the key is pressed, and then blitting another when the other key is presses. But I do not knoww how to make the original image disappear. Any thoughts on this as well? Thank you.

  • Made an answer [here](http://stackoverflow.com/a/42013186/6486738) which doesn't go through this question explicitly but gives you an example on how to create such animations. – Ted Klein Bergman Apr 13 '17 at 10:11

1 Answers1

1

You have to remember the face direction ( self.face_direction = RIGHT ) on click flip only if direction is wrong.

Alternatively, save the flipped image in face_flipped_right. Then either show original image or flipped ( flipping is nondestructive)

Serge
  • 3,387
  • 3
  • 16
  • 34