Creating tiles

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);
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);

I’m not sure as I read this quite in a hurry, but tilearea.w = 10;
and tilearea.h = 10; will be ignored, perhaps you should check
your .x and .y.

Don’t know if it helps, again just read that fast.

RegardsOn 12 Dec 2006, at 21:41, Ochal Christophe wrote:


Kuon
CEO - Goyman.com SA
http://www.goyman.com/

“Computers should not stop working when the users’ brain does.”

-------------- next part --------------
A non-text attachment was scrubbed…
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2434 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20061212/1e39e5f7/attachment.bin

Hello Ochal,

Tuesday, December 12, 2006, 8:41:00 PM, you wrote:

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.

  1. Don’t do this - you will be wasting RAM. Keep your font as one big
    surface, and use appropriate rects to cut out the letters when you
    render the text

  2. Your tiles array will be full of NULL pointers, so
    SDL_BlitSurface() fails as it doesn’t create surfaces.–
    Best regards,
    Peter mailto:@Peter_Mulholland

Hello Ochal,

Tuesday, December 12, 2006, 8:41:00 PM, you wrote:

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.

  1. Don’t do this - you will be wasting RAM. Keep your font as one big
    surface, and use appropriate rects to cut out the letters when you
    render the text

Hmm… that’s true, didn’t think about it, thx

  1. Your tiles array will be full of NULL pointers, so
    SDL_BlitSurface() fails as it doesn’t create surfaces.

Well, that explains alot :wink:

Thx!On Tue, 2006-12-12 at 20:53 +0000, Peter Mulholland wrote: