Created the TileSheetManager class

This class will manage the large(ish) number of tile sheets for a specific
map.
This commit is contained in:
Kayne Ruse
2013-10-21 23:53:36 +11:00
parent 7e603ffa89
commit 0b4e6003d6
4 changed files with 101 additions and 23 deletions
+1 -14
View File
@@ -21,12 +21,8 @@
*/
#include "tile_sheet.hpp"
#include "utility.hpp"
#include <stdexcept>
int TileSheet::rangeEnd = 0;
SDL_Surface* TileSheet::LoadSurface(std::string fname, Uint16 w, Uint16 h) {
//setup the image
image.LoadSurface(fname);
@@ -37,14 +33,6 @@ SDL_Surface* TileSheet::LoadSurface(std::string fname, Uint16 w, Uint16 h) {
xCount = image.GetSurface()->w / w;
yCount = image.GetSurface()->h / h;
totalCount = xCount * yCount;
//cache the name
name = truncatePath(fname);
//set the range
begin = rangeEnd;
end = begin + totalCount;
rangeEnd += totalCount;
}
SDL_Surface* TileSheet::GetSurface() {
@@ -55,12 +43,11 @@ void TileSheet::FreeSurface() {
image.FreeSurface();
totalCount = xCount = yCount = 0;
begin = end = -1;
name.clear();
}
void TileSheet::DrawTo(SDL_Surface* const dest, int x, int y, int tileIndex) {
if (!InRange(tileIndex)) {
throw(std::runtime_error("Tile index out of range of Tile Sheet"));
throw(std::invalid_argument("Tile index out of range"));
}
Sint16 clipX = (tileIndex-begin) % xCount * image.GetClipW();
Sint16 clipY = (tileIndex-begin) / xCount * image.GetClipH();