[SDL] SDL Surface Array
David Olofson
david at olofson.net
Sat Feb 21 11:31:01 PST 2004
On Saturday 21 February 2004 19.18, Brønnum-Hansen wrote:
[...]
> > So, use arrays of *pointers* to SDL_Surfaces instead.
>
> Okay, I've read about pointers and understand them.
> But I still don't understand how I should use them here.
> Because, the pointers needs a type, don't they?
A pointer *has* a type; it's a pointer. Actually, it's also a pointer
to something; in this case a pointer to an SDL_Surface struct - or
"SDL_Surface *", expressed in C/C++.
> Please, could I get a short example?
//The surfaces
SDL_Surface *surfaces[8];
//Load graphics
surfaces[0] = IMG_Load("picture1.png");
surfaces[1] = IMG_Load("picture2.png");
surfaces[2] = IMG_Load("picture3.png");
...
surfaces[7] = IMG_Load("picture8.png");
//(Add error checking!)
//Do kewl stuff
...
//Free surfaces
for(int i = 0; i < 8; ++i)
SDL_FreeSurface(surfaces[i]);
[...]
> I really hope you don't consider this as off-topic because I really
> need this help and don't know where I'm supposed to get it, if not
> here.
It *is* off-topic, as it's not specific to SDL in any way whatsoever.
We're talking about very basic C/C++ stuff. If you've read something
that actually explains pointers in a comprehensible way, this stuff
should be quite obvious.
Google comes up with countless hits on books and stuff about C and C++
for beginners, and I guess there are a few on-line resources as well,
though I didn't find one right away. I'd recommend getting one of
those books anyway, though I don't know which ones are best. (The one
I learnt C from was in swedish, and has no translations AFAIK. Not
*that* far form danish, but you have to be pretty much fluent in the
language for this kind of litterature.)
//David Olofson - Programmer, Composer, Open Source Advocate
.- Audiality -----------------------------------------------.
| Free/Open Source audio engine for games and multimedia. |
| MIDI, modular synthesis, real time effects, scripting,... |
`-----------------------------------> http://audiality.org -'
--- http://olofson.net --- http://www.reologica.se ---
More information about the SDL
mailing list