0

I´m starting with cocos2d for python and would like to flip a sprite among its x (or y) axis. From what I gather this should be possible with the underlying pyglet lib but I couldn´t figure out how. I tried it like this:

class Ninja(cocos.sprite.Sprite):
    def __init__(self):
        super(Ninja, self).__init__("Idle__000.png")
        self.flip_x = True

I think there should be a flip() or transform() function somewhere, but couldn´t find anything going through cocos2d-python and pyglets sources.

How can I flip a sprite after instantiation?


Alternative approach: If I can´t flip a sprite programmatically, I´d try to just swap out the picture with an already flipped version. How would I do this then?

perelin
  • 1,367
  • 1
  • 17
  • 32

1 Answers1

2

Hi if there is not flip method on Sprite try set property scale_x or scale_y to -1. Or make Ninja Sprite with scale parameter. There is list of parameters for sprite initialization.

http://python.cocos2d.org/doc/api/cocos.sprite.html?highlight=cocos.sprite.sprite#cocos.sprite.Sprite

Elensar
  • 124
  • 1
  • 9
  • I just found this answer and I'd like to say that it works but not the way you thought. By changing the scale_x/y property to a negative number it actually makes the width/height property a negative number too which is not what you need because it will cause a lot of trouble. I couldn't find a better way to flip a sprite than to change the source code a little so that it wouldn't be a negative width for my game object. If you change the width/height property to return the absolute value of the scales multiplied together, you can use the negative scale to flip the image. – Gábor Fekete Sep 17 '18 at 01:50