Skip to content

Instantly share code, notes, and snippets.

@beakr
Created February 17, 2014 04:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beakr/9044998 to your computer and use it in GitHub Desktop.
Save beakr/9044998 to your computer and use it in GitHub Desktop.
#include <engine/sprite.hh>
#include <string>
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
namespace mnts
{
Sprite::Sprite(SDL_Surface * gameScreen, std::string texture, int x, int y)
{
this->gameScreen = gameScreen;
this->texture = texture;
this->x = x;
this->y = y;
}
Sprite::~Sprite()
{
delete gameScreen;
}
void Sprite::create()
{
SDL_Surface * loadedTexture = NULL;
SDL_Surface * optimizedTexture = NULL;
loadedTexture = IMG_Load(this->texture.c_str());
if (loadedTexture != NULL) {
optimizedTexture = SDL_DisplayFormat(loadedTexture);
SDL_FreeSurface(loadedTexture);
}
SDL_Rect pos;
pos.x = this->x;
pos.y = this->y;
SDL_BlitSurface(optimizedTexture, NULL, this->gameScreen, &pos);
}
}
#ifndef __MNTS_SPRITE_HH__
#define __MNTS_SPRITE_HH__
#include <string>
#include <SDL/SDL.h>
namespace mnts
{
class Sprite
{
public:
int x;
int y;
std::string texture;
SDL_Surface * gameScreen;
Sprite(SDL_Surface * gameScreen, std::string texture, int x, int y);
~Sprite();
void create();
};
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment