Search code examples
cocos2d-iphone

How do I flip sprites horizontally in cocos2d for iphone


I only know rotation property of CCNode may have something to do with it. But I want to flip a sprite horizontally, not rotated.


Solution

  • If you mean you would like to horizontally flip a CCNode, you simply do:

    sprite.scaleX *= -1;
    

    (or: sprite.scaleX = -sprite.scaleX); if your sprite is not scaled at all in the first place, you might do simply:

    sprite.scaleX = -1;
    

    The CCSprite class has got a flipX/flipY methods that may serve your purpose. Keep in mind the following difference in behaviour, though:

    @note Flipping does not flip any of the sprite's child sprites nor does it alter the anchorPoint.

    If that is what you want, you should try inversing the CCNode scaleX property: sprite.scaleX *= -1.0;.