Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flip CCSprite Horizontally After Adding to Layer

I'm creating a fish for an app that swims to random locations on the screen. Before the fish begins swimming towards the next location, it rotates to the angle between its starting point and the target point.

What I'm trying to figure out is: if (target.x < start.x), I need to flip the sprite horizontally.

The problem is, after I create the sprite and addChild to the layer, I can't set the flipX property of the sprite using [sprite setFlipX].

Is setFlipX locked after the sprite is added to the layer? How can I get around this? Is my only solution to animate?

like image 583
Matisse VerDuyn Avatar asked Feb 22 '23 13:02

Matisse VerDuyn


1 Answers

To flip and preserve any previous scaling, use:

sprite.scaleX *= -1.f;

After you've done this you should not use the property sprite.scale any more as it includes an assertion of scaleX == scaleY.

like image 189
Danyal Aytekin Avatar answered Mar 04 '23 01:03

Danyal Aytekin