开发者

How do I add animation to an iPhone app?

So I came from a Flash background where I can animate in timeline. I开发者_如何学C've completed the Beginning iPhone Development book and just realized that I still don't know how to get an animation in. I'm guessing I need to import png sequences?

Can anyone point me to an appropriate place to learn more about this topic? I want to make a game and my game objects need to animate.

Thanks in advance!!


The simplest type of animation, moving things around and fading in and out, can be done with a few static methods of UIVIew. You can affect the center, bounds, transform matrix and alpha level of one or more views.

[UIView beginAnimations:nil context:nil];
[fadingOutView setAlpha:0.0];
[slidingView setCenter:CGPointZero];
[shrinkingView setFrame:CGRectZero];
[fadingInView setAlpha:1.0];
[spinningView setTransform:CGAffineTransformMakeRotation( M_PI )];
[UIView commitAnimations];

Animations start with the current state of the view and interpolate to the state assigned between begin and commit animation. So if fadingInView already had an alpha of 1.0 (the default) there would be no change.

If you are unfamiliar with static methods [UIView method]; means call method on the class not an instance.

Using other UIView static methods you can control several details of the animation. Every UIView has a CALayer that also has a few properties that can be animated, the most interesting of which is the 3D transform property.

If the basic animation is not sufficient for you needs, you can either look into CAAnimation and related classes, or look to a third party animation library.

I think the best place to start learning is in your code, since you are just transitioning from Flash. Look at the very bottom of UIView.h to see the animation methods. Make a few views and move them around.


Take a look at cocos2d for iPhone. It has a good framework for handling sprites, animation (frame based and motion) as well as a lot of other stuff.

http://www.cocos2d-iphone.org

You can of course do all off this on your own with core graphics and core animation, but an API like cocos2d takes care of a lot of the nitty gritty details for you.


The Beginning iPhone Development book does not talk much about animation. You may read more about animation from Apple documentation, and play with some samples from Apple, such as the Touches.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜