4

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?

Matisse VerDuyn
  • 1,148
  • 15
  • 40

2 Answers2

5

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.

Danyal Aytekin
  • 4,106
  • 3
  • 36
  • 44
3

Try flipping it by setting the scaleX to -1:

sprite.scaleX = -1;

Also, for what it's worth, you should be able to set the flipX boolean after a node is added as a child. Something else must be going on if you can't.

hspain
  • 17,528
  • 5
  • 19
  • 31