The code below is where I am right now, I’ve made it so I can click a button and change from one sprite on a sprite sheet to another. The fundamentals I’m working out may be crap, I don’t really know what I’m doing! By all means, steer me straight if this is so.
What I want to know is how to loop over all the sprites in my sprite sheet. Currently I can just flip between the first and second one (only one time) via button click.
UIImageView test = new UIImageView();
test.Image = UIImage.FromFile("necromancerSpriteSheet.png");
CGImage img = test.Image.CGImage;
CALayer layer = new CALayer();
layer.Contents = img;
layer.Bounds = new RectangleF(0, 0, 128, 128);
layer.Position = new PointF(150, 250);
UIImageView theImage = new UIImageView();
layer.ContentsRect = new RectangleF(0, 0, 0.33f, 0.33f);
layer.RemoveAllAnimations();
theImage.Layer.AddSublayer(layer);
button.TouchUpInside += (s, e) => {
layer.ContentsRect = new RectangleF(0.33f, 0, 0.33f, 0.33f);
layer.RemoveAllAnimations();
theImage.Layer.AddSublayer(layer);
};
I would expect the process would be to have all the sublayers loaded/initialized then simply loop over them in some way. I haven’t had any luck figuring out how to achieve this yet though.
Here is my test spritesheet if it helps…

There are many ways of solving this problem, but if you want to use CoreAnimation to drive the animation on the sheet, my suggestion is that you use a keyframe animation (CAKeyFrameAnimation) to drive the animation.
To simplify things, I would merely put all of the items in a single row, and then use something like:
You might need to tweak the animation above a little, I did the above without testing.