Loading Images in SDL and Scope
Posted: Wed Mar 04, 2009 11:02 pm
So I'm working my way through Lazy Foo's SDL tutorial and I found something in the code that suprised me. Hopefully someone can clear this up for me.
In his tutorials he usually creates global variables for images, which is fine, but since I am still learning I'd like to stick to OO design as much as possible. He loads all the surfaces with images using a function like:
So if I wanted to make something similar in OO fasion, creating the variables in the functions in which I will use them, should I just load them after making them instead of creating a seperate function to handle it?
I realize I wouldn't have the function to test whether everything loaded ok, but I guess I could make a function like:
In his tutorials he usually creates global variables for images, which is fine, but since I am still learning I'd like to stick to OO design as much as possible. He loads all the surfaces with images using a function like:
Code: Select all
bool load_files()
{
//Load the image
image = load_image( "x.png" );
background = load_image( "background.png" );
message = load_image( "dude.png");
dots = load_image( "preview.png" );
//If there was an error in loading the image
if( image == NULL )
{
return false;
}
//If everything loaded fine
return true;
}
I realize I wouldn't have the function to test whether everything loaded ok, but I guess I could make a function like:
Code: Select all
bool didItLoad(SDL_Surface* tester)
{
if( tester == NULL)
{
return false;
}
return true;
}