Smooth animation in Cocos2d for iOS

Posted by MrDatabase on Game Development See other posts from Game Development or by MrDatabase
Published on 2011-11-21T23:11:08Z Indexed on 2011/11/22 2:11 UTC
Read the original article Hit count: 407

I move a simple CCSprite around the screen of an iOS device using this code:

[self schedule:@selector(update:) interval:0.0167];

- (void) update:(ccTime) delta {
    CGPoint currPos = self.position;
    currPos.x += xVelocity;
    currPos.y += yVelocity;

    self.position = currPos;
}

This works however the animation is not smooth. How can I improve the smoothness of my animation?

My scene is exceedingly simple (just has one full-screen CCSprite with a background image and a relatively small CCSprite that moves slowly).

I've logged the ccTime delta and it's not consistent (it's almost always greater than my specified interval of 0.0167... sometimes up to a factor of 4x).

I've considered tailoring the motion in the update method to the delta time (larger delta => larger movement etc). However given the simplicity of my scene it's seems there's a better way (and something basic that I'm probably missing).

© Game Development or respective owner

Related posts about animation

Related posts about cocos2d-iphone