Better Animation

Discussion in 'iOS Programming' started by Darkroom, Sep 12, 2009.

  1. Darkroom Guest

    Darkroom

    Joined:
    Dec 15, 2006
    Location:
    Montréal, Canada
    #1
    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?
     
  2. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #2
    Is there a reason you use a transform rather than moving the center?
     
  3. Darkroom thread starter Guest

    Darkroom

    Joined:
    Dec 15, 2006
    Location:
    Montréal, Canada
    #3
    for this specific animation, a translation is the only transformation applied, so for me it's just easier. is moving the center better for some reason? would it make the animation smoother?
     
  4. North Bronson macrumors 6502

    Joined:
    Oct 31, 2007
    Location:
    San José
    #4
    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.
     
  5. Darkroom thread starter Guest

    Darkroom

    Joined:
    Dec 15, 2006
    Location:
    Montréal, Canada
    #5
    sorry, i meant it's more choppy.

    it is a UIImage

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

    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?
     
  6. North Bronson macrumors 6502

    Joined:
    Oct 31, 2007
    Location:
    San José
    #6
    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.
     

Share This Page