# Setting up images for frame animation

I am learning the basics of iPhone frame animation. I have code that loops through 15 images to do an animation:

- (void)viewDidLoad
{
UIImageView *iv = [[UIImageView alloc] initWithFrame:CGRectMake(40, 40, 95, 70)];
NSMutableArray *arr = [[NSMutableArray alloc] init];
for(int i = 1; i <=15; i++){
UIImage *img = [UIImage imageNamed:[NSString stringWithFormat:@"someImage_%02d", i]];
}
iv.animationImages = arr;
iv.animationDuration = 1.0 / 2;

[iv startAnimating];
}


I want to load images of Link from a picture I found on the internet. How can I take this image (available as a png) and load the unique parts of the image? I have heard of people putting multiple images into a single PNG to improve performance. How do I extract the individual images into an array for use in code like the above?

Please keep in mind this is my first time doing frame animation. I realize this code can likely be improved. I'm trying to keep things simple.

• To use a sheet of images, you may have to manipulate the UV coordinates in the shader to access the proper character pose for each frame. I'll put some thought into how you can extract the images before I try and provide an answer. In the mean time, you might want to grab yourself a copy of Blender since my answer will definitely require this. – MarcClintDion Jun 27 '14 at 18:11
• I have this partially working already using Blender so I think you should start a question on the Blender Stack Exchange forum that is mostly the same, but leave out the code part since that will confuse people there. I will add the solution that I'm working on now, and maybe someone else will have an even better solution. Basically I've set up the camera to zoom into one of the link images and I'm setting up an animation for the camera that will move along the image and render out each component as a separate image. At this point, it's just a matter of getting the accuracy down. – MarcClintDion Jun 27 '14 at 18:35
• Is this the "normal" way of doing things if you will? Or are individual images more common? Using blender and all that seems like a lot of effort. – P.Brian.Mackey Jun 27 '14 at 18:47
• Those animation sheets are set up for efficiency and ease of use as you've already stated. You may have to ask another question here about how to write a shader that can alter the UV coordinates per frame to select the proper image sequence but that is going to be a tricky situation since the ordering of those images seems kindof all over the place. You will need a fairly complicated setup to select the proper UV coordinates for each of the animations available in that set. Anyways, I was planning on adding the .blend file setup and all the individual images to the answer I provide. – MarcClintDion Jun 27 '14 at 19:08
• I have the first row rendered out but I'm concerned that I may be off by a few fractions of pixels by the time the camera moves across the whole sheet so I'm working on refining this a bit. Even though StackExchange forums are not about doing other people's work for them I don't mind doing this set to help you get started. However, you are going to run into problems here when you start doing all of the other characters because you will have several thousand images to load and keep track of. Separating them all is the easy part here. – MarcClintDion Jun 27 '14 at 19:25