[SDL] Creating tiles
Ochal Christophe
ochal at kefren.be
Tue Dec 12 12:41:00 PST 2006
Hi all,
I'm currently trying to write a routine to load tiles into an array of
*surfaces from a png file, but BlitSurface fails to copy the parts of
the image into the proper cells of the array.
I'm hoping someone can tell me what i did wrong.
Oh, the tiles are actually used to hold a fixed width font sized 10*10.
This is the code:
SDL_Surface *buffer = NULL;
SDL_Surface *tiles[127];
SDL_Rect tilearea;
int i;
buffer = IMG_Load(tilefile);
if (buffer == NULL)
{
fprintf(stderr, "Couldn't load %s: %s\n", tilefile, \
SDL_GetError());
return 1;
}
else
{
/* file loaded, blit the tiles to the proper cells */
for (i = 0;i<127;i++)
{
tilearea.x = 0;
tilearea.y = i*10;
tilearea.w = 10;
tilearea.h = 10;
if (SDL_BlitSurface(buffer, &tilearea, tiles[i], \
NULL) < 0)
{
fprintf(stderr, "Failed blitting the tile into the cell \
\n", SDL_GetError());
}
}
SDL_FreeSurface(buffer);
More information about the SDL
mailing list