I wanted to know if, for a game, I can store a series of pointers to image data within an array to cycle through it and repeat the frames for an animation of something.
Like, say, five frames of a ball rotating. Can I store a function call to a pointer of an image surface within an array, and have the array cycled through using a for loop or such within another function and have the frames updated when necessary?
Am I on the right track here for animation in games or no?
And please don't dump any "complications" here. Thank you!
First, I recomend you using a vector instead of an array and putting it into a class (say AnimatedSprite).
Then, instead of just looping throught the vector, make a class (say Animation) that will make the job with an update method and on which you can specify the times frames between each frames, the number of repetition, the way you want to cycle between the images, if you want to turn animation on or off...
You can make an array of any type of objects, as long as they all have the same type.
It is possible to store functions (pointers to them) in an array, but you don't need that at all.
To make an animation, you don't iterate through all of the frames. You should have a variable 'f' marking which frame needs to be drawn next. On each cycle of your draw loop, redraw my_array[f]. Then, after some fixed time (like 10 frames. you'll need another counter), increment f, or, if it gets too large, set it to 0.
You can make an array of any type of objects, as long as they all have the same type.
What do you mean by "same type?"
And I don't like the other ideas, they complicate it too much. Especially the OOP idea. I'm sorry. I just wanted some input, not OOP thrown at me(I despise OOP and will never use it). >.<
In my head OOP is not suiting to my mental eye/style for programming.
@bluecoder, if you're not aware of function pointers, see http://www.cprogramming.com/tutorial/function-pointers.html
And since a function pointer is a type, you can make an array of them. The syntax is ugly unless you use a typedef. I don't remember what it is now..
I don't think I "thrown you OOP", you can perfectly implement what i explained whithout the keyworld class, make a struct if you want and if you prefer using arrays instead of vectors that doesn't change the problem.