Will arrays store anything?

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.
Last edited on
You may want to start from something more basic if you don't know what types and arrays are (I mean a tutorial).
It is possible to store functions (pointers to them) in an array,


@hamsterman : I am not able to get it . . can you elobrate on this .
It's a new year and Spoonlicker is back.
What a start...

@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.
spoon licker wrote:
It's still OOP if it confuses me.

That's how I am able to identify something useless: being it OOP.

Don't get on my nerves.


If helping you gets on your nerves then who is going to bother?

If you ask a C++ question you will get C++ answers.
SpoonLicker1 wrote:
If it's getting on my nerves then it's obviously not helping Einstein.

I remain helpless here because you ego-driven tyrants keep pushing your overly "essential" programming paradigms at me.

I want to program not learn how to do things in a certain sense.

I do things MY sense. Can't deal with it then you're not good enough to help me.

All in all, in the end, I remain untaught from the helpless members of the Cplusplus and GameDev community.

I asked a question .... I sure didn't get an answer that was relevant and suitable though.

Does it help you sleep at night knowing you're a tyrant, Fidel?


The only tyrant not helping you and holding you back is yourself ;o)

The sooner you drop your attitude and start treating people with respect, the sooner you will actually learn something!

No one can teach you anything, you are the one who has to learn. The only thing standing in your way is you.
thanks hamsterman ..for the link of function pointer .
cin.getline(arr,50,'\n');

cout<<"\n\t Reverse words are = ";

for(int i=0;i<50;i++)

{
if(arr[i]=='\0') //or i have also try if (arr[i]==' ')

{

cout << strrev (arr)<<endl;

}//end if

}//end for
my problem is that i want only reverse word not complete strings of array.but i failed ,any one can tell me please what is my weekness?
Last edited on
Topic archived. No new replies allowed.