This example shows how to use an IsoTileSet. It allows to manage images that contain multiple tiles.
#include "SDL_Tools.h" #include "IsoTileSet.h" void testTileSet(SDL_Surface* screen) { int currentFrame = 0; int x = screen->w / 2; int y = screen->h / 2; //Create a new tileset object: IsoTileSet ts; //Load the tileset image: ts.loadTileset("CaveMan_Animation.bmp"); //Do an animation loop (and listen to SDL events, too) bool done = false; SDL_Event event; while (!done) { //Clean up back buffer: SDL_FillRect(screen, NULL, 0); //Draw frame: ts.putTile(screen, x, y, currentFrame); //Put another tile to check colour keying: ts.putTile(screen, x+35, y-20, currentFrame); //Flip the back buffer: SDL_Flip(screen); //Take next frame: currentFrame ++; if(currentFrame >= ts.getTileCount()-1) { currentFrame = 0; } //Lock the frame rate: SDL_Delay(100); if(SDL_PollEvent(&event)) { switch (event.type) { case SDL_KEYDOWN: /* Any key quits the application... */ case SDL_QUIT: done = true; break; } } } } int main(int argc, char* args[]) { /* Initialize SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError()); return 1; } SDL_Surface* screen = createScreen(640, 480, "TileSet test", SDL_HWSURFACE | SDL_DOUBLEBUF); testTileSet(screen); SDL_Quit(); return 0; }