I\'m programming a game on my iPhone, and I have an image I want to animate, say a walking person in a bitmap. The bitmap changes over time. How do I add the bitmaps to the
You can do it with a CAKeyframeAnimation.
I just wrote this and didn't test it - but should get you on the right path. Load all your frames into an NSArray then set the 'values' of the animation to the frames array.
NSArray *walkFrames = [[NSArray arrayWithObjects:
[UIImage imageNamed:@"walk.00000.png"],
[UIImage imageNamed:@"walk.00001.png"],
[UIImage imageNamed:@"walk.00002.png"],
[UIImage imageNamed:@"walk.00003.png"],
[UIImage imageNamed:@"walk.00004.png"],
[UIImage imageNamed:@"walk.00005.png"],
[UIImage imageNamed:@"walk.00006.png"],
[UIImage imageNamed:@"walk.00007.png"],
[UIImage imageNamed:@"walk.00008.png"],
[UIImage imageNamed:@"walk.00009.png"],
nil] retain];
CAKeyframeAnimation *anim = [CAKeyframeAnimation animation];
anim.keyPath = @"contents";
anim.duration = 2.f;
anim.values = walkFrames;
anim.calculationMode = kCAAnimationLinear;
anim.repeatCount = HUGE_VAL;
[myView addAnimation:anim forKey:@"myFlipAnimation"];