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.