Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Here is my function, it makes random point on the ground and makes my sprite go there. If the x position of location is less then position of my sprite, I flip my sprite so it looked left (it looks right by default). But this is not working at all. I tried different flip methods but none work! Please help what is wrong?

- (void) wander
    CGPoint rand = CGPointMake(CCRANDOM_0_1() * 270 , CCRANDOM_0_1() * 140 );

    float distance = ccpDistance([currentSprite position], rand);
    float speed = distance / 2;
    ccTime time = distance / speed;
    CCAction *move = [CCMoveTo actionWithDuration:time position:rand];

    if (currentSprite.position.x > rand.x)

       currentSprite.flipX = YES;
    else {
        currentSprite.flipX = NO;

    [self runAction:move];

There is no problem with this code. Problem was that I was trying to flip sprite that was a child of my Pet object. When I tried flipping sprite everything worked just fine. If anybody could explain that, would be great.

share|improve this question
up vote 2 down vote accepted

You can also try flipping it by using the scale:

currentSprite.scaleX *= -1.f;

You should also ensure that currentSprite is the sprite that contains the texture you want to flip, and is not a parent of the sprite that contains the texture you want to flip. See the documentation about flipX for more info.

share|improve this answer
I think the problem is in another method, can you please check out this question… – Dvole Aug 10 '12 at 17:19
Have you tried the scale method? – Byte56 Aug 10 '12 at 17:23
Yes, didn't help. – Dvole Aug 10 '12 at 17:24
Actually I have found the problem. I have composite class, Pet that contains sprite as property. I tried flipping that sprite and that didnt work. When I tried to flip pet it work. Can you please explain that behavior? Thank you for quick responce anyway. – Dvole Aug 10 '12 at 17:25
I cannot explain that. If I'm reading correctly, it seems contrary to the documentation. Glad you were able to solve it. – Byte56 Aug 10 '12 at 17:32

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.