How to flip sprites horizontally in cocos2d for iphone

I only know that the CCNode rotation property may have something to do with this. But I want to flip the sprite horizontally, not rotate.

+3


source to share


4 answers


If you want to flip horizontally CCNode

, you simply do:

sprite.scaleX *= -1;

      

(or :) sprite.scaleX = -sprite.scaleX

; if your sprite doesn't scale at all, you can do it simply:



sprite.scaleX = -1;

      

The class CCSprite

has methods flipX

/ flipY

that can serve your purpose. Keep in mind the following difference in behavior :

@note Flipping does not flip any of the sprites or change the anchorPoint.

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

.

+8


source


The accepted answer is incorrect (or outdated). What you should actually be using:

sprite.flipX=YES;

      

and



sprite.flipX=NO;

      

to cancel it

+12


source


YOU CAN TRY THIS:

CCSprite* heroSprite = (CCSprite*) _character.children[0];

      

Then use the heroSprite function like:

    heroSprite.flipX = YES;

      

Works for node.

+1


source


In current version cocos2d-js (3.8): Try it,

sprite.flippedX = true; //for flipping horizontally.
sprite.flippedY = true; //for flipping vertically.

      

+1


source







All Articles