perelin
perelin

Reputation: 1448

How to flip a sprite among X or Y axis in cocos2d-python

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?

Upvotes: 0

Views: 714

Answers (1)

Elensar
Elensar

Reputation: 124

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

Upvotes: 2

Related Questions