I tend to make all of my SDL_Surfaces* private to the class they're used in, then I use accessor functions to change what the SDL_Surface Pointers point to.
The only exception to this rule, is I keep the main screen surface global(but theres nothing that says you can't stick the screen into a class, and write some accessor functions)
Heres an example of how I would implement an image loading function, loading a spritesheet into an object with an SDL_Surface*
Code: Select all
// sprite.h
class Sprite
{
private:
SDL_Surface* Image;
public:
void Load_Sprite(const char* Filename);
Sprite(){Image = NULL ;}
};
//sprite.cpp
void Sprite::Load_Sprite(const char* Filename)
{
if(Image != NULL)
{
SDL_FreeSurface(Image);
Image = NULL;
}
Image = Load_Image(Filename); // I'm just using the Load_Image function from lazy foo,
//this is just implied so I don't have to type it out :P
// I implement it as a library function, so it's global, but you don't have to write it again and again
// you could make it a class method, but whatever :-)
}
I'm not an OO expert, but my main aim is to keep everything managed and encapsulated, I try and prevent un needed access (when you thnk about it, do you really need other objects to access an SDL_Surface*? if you do all of your drawing within the object, then I don't see any point)
Hope this helped
---------------------------------------------------------------------------------------
I think I can program pretty well, it's my compiler that needs convincing!
---------------------------------------------------------------------------------------
And now a joke to lighten to mood :D
I wander what programming language anakin skywalker used to program C3-PO's AI back on tatooine? my guess is Jawa :P