Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 281
Han Pengbo Avatar asked Feb 17 '13 11:02

Han Pengbo


2 Answers

The accepted answer is wrong (or outdated). What you actually should use is:

sprite.flipX=YES;

and

sprite.flipX=NO;

to reverse it

like image 200
Sven Avatar answered Jan 03 '23 14:01

Sven


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;.

like image 25
sergio Avatar answered Jan 03 '23 14:01

sergio