Rotate CCSprite horizontally after adding to layer

I create a fish for an application that swims in random places on the screen. Before the fish begins to swim to the next place, it rotates an angle between the starting point and the target point.

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

The problem is that after creating the sprite and addChild for the layer, I cannot set the flipX property of the sprite using [sprite setFlipX] .

Is setFlipX installed after adding a sprite to the layer? How can I get around this? My only animation solution?

+4
source share
2 answers

To flip and save any previous scaling, use:

 sprite.scaleX *= -1.f; 

After that, you should no longer use the sprite.scale property, since it includes the statement scaleX == scaleY .

+5
source

Try flipping it by setting scaleX to -1:

 sprite.scaleX = -1; 

Also, for what it's worth, you should be able to install flipX boolean after adding node as a child. Something else must happen if you cannot.

+3
source

Source: https://habr.com/ru/post/1395466/


All Articles