I am trying to animate some UIImageViews to 'fall' down the page using CADisplayLink
to call a MoveObjects
function. However, despite the function calls being at consistent 0.0155-0.017s intervals, the animation appears to stutter every few frames, in the same way as it did when I tried using a NSTimer
to call the function. Is there anything that i'm doing wrong, which is making it stutter?
in viewDidLoad
:
displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(gameLoop)];
displayLink.frameInterval=1;
[displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
currently gameloop pnly calls UpdateObjects:
-(void)updateObjects{
timeStamp=[displayLink timestamp];
double frameTime=timeStamp-oldTime;
oldTime= timeStamp;
if (frameTime>10){
frameTime=0;
}
NSLog(@"%f",frameTime);
for (int i=0; i<objectsArray.count; i+=1) {
UIImageView *currentObject=[objectsArray objectAtIndex:i];
CGRect currentObjectFrame=[currentObject frame];
[currentObject setFrame:CGRectMake(CGRectGetMinX(currentObjectFrame), CGRectGetMinY(currentObjectFrame)+200*frameTime,CGRectGetWidth(currentObjectFrame) , CGRectGetHeight(currentObjectFrame))];
}
}