Created
February 17, 2014 04:59
-
-
Save beakr/9044998 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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