Re: Animating "contents" property of CALayer via the delegate
Re: Animating "contents" property of CALayer via the delegate
- Subject: Re: Animating "contents" property of CALayer via the delegate
- From: Oleg Krupnov <email@hidden>
- Date: Mon, 28 Sep 2009 20:00:51 +0300
Thanks, but that's not exactly what I need. I don't need to animate
"canned" sprites. I'd like to make a frame-by-frame, stop-motion
animation. I could use a NSAnimation or NSTimer object to drive the
frame motion (call layer's setNeedsDisplay on each timer event), but
I'd like to use CoreAnimation's internal timing. Is this possible at
all? I'm starting to doubt...
On Mon, Sep 28, 2009 at 5:56 PM, Matt Neuburg <email@hidden> wrote:
> On Mon, 28 Sep 2009 14:16:36 +0300, Oleg Krupnov <email@hidden>
> said:
>>I'd like to use Core Animation to create an arbitrary animation, that
>>is, I have a number of custom-drawn frames that I want to render in a
>>sequence, with a good frame rate, using the Core Animation timing
>>engine. How do I do this?
>>
>>I am looking on CAKeyframeAnimation, which could do the job using the
>>code like this:
>>
>> CAKeyframeAnimation *anim;
>> NSMutableArray *images;
>> CGImageRef im;
>> int i;
>>
>> images = [NSMutableArray array];
>> for (i = 0; i < N; i++) {
>> im = create_image (i);
>> [images addObject:(id)im];
>> CGImageRelease (im);
>> }
>>
>> anim = [CAKeyframeAnimation animation];
>> [anim setKeyPath:@"contents"];
>> [anim setValues:images];
>> [anim setCalculationMode:@"discrete"];
>> [anim setRepeatCount:HUGE_VAL];
>> [anim setDuration:1.0];
>>
>> [layer addAnimation:anim];
>>
>>However, I don't like to create all keyframe images at once, but
>>instead draw them in process of animation, when the particular frame
>>becomes the current frame, via the -[CALayer drawLayer:inContext:]
>>delegate method. How do I do this? The delegate method seems to get
>>called only once. Thanks!
>
> You might find some architectural inspiration in Matt Gallagher's
> "Asteroids" Core Animation example:
>
> http://cocoawithlove.com/search/label/CoreAnimation
>
> m.
>
> --
> matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
> A fool + a tool + an autorelease pool = cool!
> AppleScript: the Definitive Guide - Second Edition!
> http://www.tidbits.com/matt/default.html#applescriptthings
>
>
>
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden