The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
Map Editor
Thiago Nunes Leite
Guest

After successfuly solving my problem(with the help of u guys), with the maps,
and tiles, and .... forget it... I'm working on a map editor...
I'm using c/c++ and SDL.
first i have a function that opens the map file:
bool Load_Map(char *filename){

char c;
int y=0, x=0;

FILE *f = fopen(filename, "rb");

cout << "Loading map .....";

while((c = fgetc(f)) != EOF) {
if(c=='\n') {
y++;
x=0;
continue;
}
map[y][x++] = c;
}
cout << "ok" << endl;
return true;
}



and then i have the function that draws the map its located right after input
handling. The code:
for(int y=0;y<MAPHEIGHT;y++)
{
for(int x=0;x<MAPWIDTH;x++){

int i = map[y][x];

if(i==0){ Draw_BMP(x * TILESIZE, y * TILESIZE, image); }
if(i==1){ Draw_BMP(x * TILESIZE, y * TILESIZE, image2); }
if(i==2){
Draw_BMP(x * TILESIZE, y * TILESIZE, image);
Draw_BMP(x * TILESIZE, y * TILESIZE, image3);
}

}
}
SDL_Flip(screen);




It's the same method i use to draw the map on my game... but it doesn't seem
to work right with the editor, i just get a black screen :/
my map is a char map[10][10] and i'm using 32x32 tiles. I've tryied
everything.... it's seems that something is crashing SDL... :(

Thanks a lot for your attention
Best regards
Map Editor
Bill Kendrick
Guest

On Thu, Jan 05, 2006 at 02:22:51AM +0000, Thiago Nunes Leite wrote:
Quote:
After successfuly solving my problem(with the help of u guys), with the maps,
and tiles, and .... forget it... I'm working on a map editor...
I'm using c/c++ and SDL.
first i have a function that opens the map file:
<snip>
Quote:
while((c = fgetc(f)) != EOF) {
<snip>
Quote:
map[y][x++] = c;
<snip>


Quote:
and then i have the function that draws the map its located right after input
handling. The code:
<snip>
Quote:
int i = map[y][x];

if(i==0){ Draw_BMP(x * TILESIZE, y * TILESIZE, image); }
if(i==1){ Draw_BMP(x * TILESIZE, y * TILESIZE, image2); }
<snip>

Does the file in question actually contain bytes 0, 1 and 2 (0x00, 0x01, 0x02),
or the _characters_ "0", "1" and "2"?

If the latter, you need to change your "i==" tests to look more like:

if (i=='0') ...



This seems really off-topic for the SDL list...

--
-bill!
bill at newbreedsoftware.com
http://www.newbreedsoftware.com/