Hi, i?m triying to develop a tile system for a game. I start with a
example program that display some random tiles on the screen. I don?t
know if use a surface for each tile is the corret way…
I have a compiler error here ( i ?m a C newbie)
//Declarations
SDL_Surface *tiles, *screen;
…
//Dinamic Memory for the array of surfaces
n_tiles = 4;
tiles = (SDL_Surface *) malloc (n_tiles * sizeof(SDL_Surface));
if(tiles == NULL){ printf(“Error de memoria\n”); return -1; }
…
//Images load
for(i = 0; i <= n_tiles; i++){
sprintf(ruta,"%s%d%s",“tiles”,i,".png");
printf("%s", ruta);
tiles[i] = SDL_LoadBMP(ruta); /In this line the compiler says
uncompatible types assignament, with &tiles[i] = … i have an error
too./
if(&tiles[i]==NULL) printf(“Error al abrir una imagen\n”);
}
what ?s the problem? Thanks.
(Sorry for my english, i hope you can understand me)
Hi, i?m triying to develop a tile system for a game. I start with a
example program that display some random tiles on the screen. I don?t
know if use a surface for each tile is the corret way…
I have a compiler error here ( i ?m a C newbie)
//Declarations
SDL_Surface *tiles, *screen;
…
//Dinamic Memory for the array of surfaces
n_tiles = 4;
tiles = (SDL_Surface *) malloc (n_tiles * sizeof(SDL_Surface));
if(tiles == NULL){ printf(“Error de memoria\n”); return -1; }
…
//Images load
for(i = 0; i <= n_tiles; i++){
sprintf(ruta,"%s%d%s",“tiles”,i,".png");
printf("%s", ruta);
tiles[i] = SDL_LoadBMP(ruta); /In this line the compiler says
uncompatible types assignament, with &tiles[i] = … i have an error
too./
if(&tiles[i]==NULL) printf(“Error al abrir una imagen\n”);
}
what ?s the problem? Thanks.
(Sorry for my english, i hope you can understand me)
—Publicidad--------------------------------------------------------
?nete a los miles de sin pareja en Meetic… ?te vas a enamorar!
Looks like your tiles variable is pointer to SDL_Surface instead being a
pointer to pointer to SDL_Surface. So the error is correct, because you
are trying to set in SDL_Surface struct value that is pointer to
SDL_Surface struct, instead being SDL_Surface.
So use one * more in declaration and casting of the malloc.
PS. sprintf(ruta,“tiles%d.png”,i); is litle bit more readable than
sprintf(ruta,"%s%d%s",“tiles”,i,".png");On Sunday 23 February 2003 01:28, Marcos wrote:
Hi, i?m triying to develop a tile system for a game. I start with a
example program that display some random tiles on the screen. I don?t
know if use a surface for each tile is the corret way…
I have a compiler error here ( i ?m a C newbie)
//Declarations
SDL_Surface *tiles, *screen;
…
//Dinamic Memory for the array of surfaces
n_tiles = 4;
tiles = (SDL_Surface *) malloc (n_tiles * sizeof(SDL_Surface));
if(tiles == NULL){ printf(“Error de memoria\n”); return -1; }
…
//Images load
for(i = 0; i <= n_tiles; i++){
sprintf(ruta,"%s%d%s",“tiles”,i,".png");
printf("%s", ruta);
tiles[i] = SDL_LoadBMP(ruta); /In this line the compiler says
uncompatible types assignament, with &tiles[i] = … i have an error
too./
if(&tiles[i]==NULL) printf(“Error al abrir una imagen\n”);
}
From: @Marcos_Prieto_Gonzal (Marcos Prieto Gonzalez)
To:
Sent: Sunday, February 23, 2003 12:28 AM
Subject: [SDL] SDL_Surface & malloc
Hi, i?m triying to develop a tile system for a game. I start with a
example program that display some random tiles on the screen. I don?t
know if use a surface for each tile is the corret way…
I have a compiler error here ( i ?m a C newbie)
//Declarations
SDL_Surface *tiles, *screen;
…
//Dinamic Memory for the array of surfaces
n_tiles = 4;
tiles = (SDL_Surface *) malloc (n_tiles * sizeof(SDL_Surface));
if(tiles == NULL){ printf(“Error de memoria\n”); return -1; }
…
//Images load
for(i = 0; i <= n_tiles; i++){
sprintf(ruta,"%s%d%s",“tiles”,i,".png");
printf("%s", ruta);
tiles[i] = SDL_LoadBMP(ruta); /In this line the compiler says
uncompatible types assignament, with &tiles[i] = … i have an error
too./
if(&tiles[i]==NULL) printf(“Error al abrir una imagen\n”);
}
what ?s the problem? Thanks.
(Sorry for my english, i hope you can understand me)
—Publicidad--------------------------------------------------------
?nete a los miles de sin pareja en Meetic… ?te vas a enamorar! http://www.iespana.es/_reloc/email.meetic
—Publicidad--------------------------------------------------------
?nete a los miles de sin pareja en Meetic… ?te vas a enamorar! http://www.iespana.es/_reloc/email.meetic
—Publicidad--------------------------------------------------------
?nete a los miles de sin pareja en Meetic… ?te vas a enamorar! http://www.iespana.es/_reloc/email.meetic
Hi, i?m triying to develop a tile system for a game. I start with a
example program that display some random tiles on the screen. I don?t
know if use a surface for each tile is the corret way…
I have a compiler error here ( i ?m a C newbie)
//Declarations
SDL_Surface *tiles, *screen;
This is just declaring a pointer to an SDL_Surface. If you want a dynamic
array of surfaces, it should be:
SDL_Surface **tiles;
//Dinamic Memory for the array of surfaces
n_tiles = 4;
tiles = (SDL_Surface *) malloc (n_tiles * sizeof(SDL_Surface));
This bit here should allocate memory for the pointers to your surfaces, not
actual memory for the surfaces themselves. The SDL_LoadBMP later will
allocate the memory for the actual surface. Try:
tiles = (SDL_Surface *) malloc (n_tiles * sizeof(SDL_Surface));
Don’t worry, it takes some practice to get the hang of pointers in C. Good
luck.
Max Watson <@Max_Watson>On Wednesday 22 January 2003 18:46, Marcos wrote: