I have created CALayer
objects and am able to animate their movement around the screen. However, now I want to animate them to change through a set of images in a loop to create an animation (like an animated gif)
I'm fairly new to programming and very new to Cocoa so code examples welcome.
I have 15 PNG images.
EDIT: I have code that creates an NSArray
of 15 CGImageRef
objects.
Have the object that owns the array and layer (I presume there is an object that owns both) also own a timer, which sends the object a message to change the image displayed in the layer. The same object should also have an instance variable containing an index into the array.
To respond to the timer message, check whether there are any images in the array, and, if so, divide the index by the count of the array and take the remainder (%
operator). The result is the index to access; get the image from that index in the array and change the image in the layer, then add 1 to the computed index and assign it back to the variable.