How do I add animation to my iPhone app?
So I came from a flash background where I can animate in a timeline. I finished the iPhone development book and realized that I still don't know how to get the animation. I'm assuming I need to import png sequences?
Can anyone point me to a suitable place to learn more about this topic? I want to create a game and my game objects need to come to life.
Thanks in advance!
a source to share
The simplest type of animation, moving things and fading inside and out, can be done with a few static UIVIew methods. You can affect the center, borders, matrix and alpha transform 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 at the current view state and are interpolated to the state assigned between the start and the commit of the animation. So if fadingInView already had an alpha of 1.0 (the default), there was no change.
If you are not familiar with static methods, [UIView method];
means calling method in class, not instance.
Using other static methods of UIView, you can control multiple animation details. Each UIView has a CALayer, which also has several properties that can be animated, the most interesting of which is the 3D transform property.
If basic animation isn't enough for you, you can either look into CAAnimation and the related classes, or look into a third party animation library.
I think the best place to start learning is in your code, as you are just switching from Flash. Take a look at the very bottom of UIView.h to see animation methods. Make multiple views and move them around.
a source to share
Take a look at cocos2d for iPhone. It has a good structure for handling sprites, animation (frame and motion), and many other things.
You can of course do it yourself using basic graphics and basic animation, but an API like cocos2d will take care of a lot of granularity for you.
a source to share