In any tile based game I do, I like to rename the filenames of the tile graphics 0, 1, 2 and so forth, so that I can load them all into an array with one for-loop:
// Load in tilesetfor(int i = 0; i < NUM_TILES; i++){ char filename[20]; sprintf(filename, "gfx/Tiles/%d.bmp", i); tiles = SDL_LoadBMP(filename); if(!tiles) // error}
Although this works, I want to use std::string whenever I need to do any string related processing. Plus, I've heard using sprintf() is a definite no-no. So this would be the new version:
// Load in tilesetfor(int i = 0; i < NUM_TILES; i++){ std::ostringstream filename; filename << "gfx/Tiles/" << i << ".bmp"; tiles = SDL_LoadBMP(filename.str().c_str()); if(!tiles) // error}
Does the same thing, but it is now very C++-ified and it fits in well with the rest of my STL heavy code.
It can be used thusly: