Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Darkroom

Guest
Original poster
Dec 15, 2006
2,445
0
Montréal, Canada
i've been using Core Animation to accomplish animations. while shifting smaller rects of images works well, larger, fullscreen rects always suffer from lag.

Code:
[UIView beginAnimations:@"Animation" context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationRepeatCount:FLT_MAX];
			
CGAffineTransform transform = CGAffineTransformMakeTranslation(480, 0);
[myRect setTransform:transform];

[UIView commitAnimations];

in the above code, myRect hosts a UIImage that is the size of the entire screen, and the animation will move it on to the screen from the left: {-480, 0, 480, 320}. if, however, myRect and the UIImage is smaller (a fourth the size of the screen), the animation is noticeably much smoother.

what causes this? is there a remedy? i'm assuming that the UIImage needs to be redrawn for each step of the animation, which causes larger images to animate less smoothly than smaller ones.

i've used apps and games where a scrolling background doesn't have a lag, even with many other forefront, smaller animations occurring simultaneously. i've been told it's because these apps use OpenGL instead of CA, but i though CA was like an OpenGL-lite that does the same thing but only accesses basic functionality of OpenGL? is it because one is rendering vector based images while my apps are animating bitmaps that need to be continuously redrawn?
 
When you say it "lags", do you mean that there is a delay in starting the animation, or that the whole animation looks "choppy"

When you say "myRect hosts a UIImage", is myRect a UIImageView?

Also, to move offscreen, the X displacement only has to be 320, not 480 (the Y displacement). I think you just switched them around.

Core Animation shouldn't be redrawing the image bitmap for each frame, but if the image contains transparency, it might have to re-composite for each frame, which would hurt performance. You might want to try an opaque image and see if that helps.
 
When you say it "lags", do you mean that there is a delay in starting the animation, or that the whole animation looks "choppy"

sorry, i meant it's more choppy.

When you say "myRect hosts a UIImage", is myRect a UIImageView?

it is a UIImage

Also, to move offscreen, the X displacement only has to be 320, not 480 (the Y displacement). I think you just switched them around.

sorry i wasn't more clear. i was referring to landscape mode.

Core Animation shouldn't be redrawing the image bitmap for each frame, but if the image contains transparency, it might have to re-composite for each frame, which would hurt performance. You might want to try an opaque image and see if that helps.

interesting. i never though of that before. yes, the images i'm animating have quite a bit of transparency in them so underlying layers can be seen thru them. i also have transparency on UIImages which user's can drag, resetting the rect's frame on every touchesMoved call. these images also have transparency, so would removing the transparency (if possible to do so) help performance? does the amount of transparency matter, or is it that if there is any transparency at all, even a bit to make a rounded corner, performance will be hurt?
 
interesting. i never though of that before. yes, the images i'm animating have quite a bit of transparency in them so underlying layers can be seen thru them. i also have transparency on UIImages which user's can drag, resetting the rect's frame on every touchesMoved call. these images also have transparency, so would removing the transparency (if possible to do so) help performance? does the amount of transparency matter, or is it that if there is any transparency at all, even a bit to make a rounded corner, performance will be hurt?

Animating strictly opaque layers will definitely give you a boost in performance.

I'm not sure how Apple handles the compositing: if ten percent of the pixels requite compositing what are the performance gains versus ninety percent requiring compositing. This might be in the documentation.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.