Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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).

share|improve this question

1 Answer 1

up vote 2 down vote accepted

you can try this code:

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

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

    self.position = currPos;
}

this way you are using the delta time provided to you, it means object will move with the same speed no matter how many times update function is called in one second. it also should help your animation look smoother.

share|improve this answer
    
Definitely a good idea. However calling scheduleUpdate instead of schedule:interval: worked much better. –  MrDatabase Nov 25 '11 at 1:14
    
@MrDatabase that's for you to decide, each of those functions have their own benefits in certain situations, but in this case I agree with calling scheduleUpdate –  Ali.S Nov 25 '11 at 8:27

Your Answer

 
discard

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.