I would like to make the following code either part of a class or available to be used by a class, this code is part of lazy foo’s tutorial #2, any ideas?
//Temporary storage for the image that's loaded
SDL_Surface* loadedImage = NULL
//The optimized image that will be used
SDL_Surface* optimizedImage = NULL;
//Load the image
loadedImage = SDL_LoadBMP( filename.c_str() );
//If nothing went wrong in loading the image
if( loadedImage != NULL )
{
//Create an optimized image
optimizedImage = SDL_DisplayFormat( loadedImage );
//Free the old image
SDL_FreeSurface( loadedImage );
}
//Return the optimized image
return optimizedImage;
How much class design have you done before? Something like this comes to my
mind:
class Sprite
{
private:
SDL_Surface* image;
public:
float x, y;
Sprite()
: image(NULL), x(0), y(0)
{}
Sprite(SDL_Surface* image)
: image(image), x(0), y(0)
{}
void draw(SDL_Surface* screen)
{
SDL_Rect dest = {x, y, 0, 0};
SDL_BlitSurface(image, NULL, screen, &dest);
}
};
Jonny DOn Tue, Apr 20, 2010 at 9:20 AM, cndr.mike <cndr.backup at yahoo.com> wrote:
I would like to make the following code either part of a class or
available to be used by a class, this code is part of lazy foo’s tutorial #2, any ideas?
//Temporary storage for the image that's loaded
SDL_Surface* loadedImage = NULL
//The optimized image that will be used
SDL_Surface* optimizedImage = NULL;
//Load the image
loadedImage = SDL_LoadBMP( filename.c_str() );
//If nothing went wrong in loading the image
if( loadedImage != NULL )
{
//Create an optimized image
optimizedImage = SDL_DisplayFormat( loadedImage );
//Free the old image
SDL_FreeSurface( loadedImage );
}
//Return the optimized image
return optimizedImage;