Page 1 of 2
Custom file formats
Posted: Wed Mar 04, 2009 7:24 pm
by Cole S.
Hi, i am trying to make my own file format for 2d maps, and i have googled it, but i can't seem to get any good information on how to create it... any help?
Re: Custom file formats
Posted: Wed Mar 04, 2009 7:28 pm
by Ginto8
Just name the file whatever you want.... You could make it "cow.moo", "chicken.fowl", ANYTHING.
hope I helped
Re: Custom file formats
Posted: Wed Mar 04, 2009 7:46 pm
by JaxDragon
I would recommend saving them all as one format(PNG for example). Once the tiles are saved as a PNG, just rename them to have any extension you want. Load them using the same way you would load a png, except your file name shouldnt end with png ^^
Re: Custom file formats
Posted: Wed Mar 04, 2009 8:00 pm
by avansc
i think he is refering to making binar files, not noramal ones
Re: Custom file formats
Posted: Wed Mar 04, 2009 8:43 pm
by Cole S.
I'm talking about having a custom 2d MAP format that i can load into my game engine... not just renamed files.
Re: Custom file formats
Posted: Wed Mar 04, 2009 8:52 pm
by Ginto8
As in a file containing a list of all the tile types and stuff in a map/level? If so, just name the file whatever you want.
If you're talking about something similar to saving an image from raw data, I have no clue.
Re: Custom file formats
Posted: Wed Mar 04, 2009 9:06 pm
by Cole S.
i dont mean a file as in "C:\Program Files" i mean a file format, as in map.<format here> that a game engine can load, it contains the tiles for the map as well as the positions and if it is collidable, as well as some other stuff
Re: Custom file formats
Posted: Wed Mar 04, 2009 10:18 pm
by Ginto8
That's what I meant the first time. The format doesn't matter really, so long as it is a text file (not necessarily .txt, just containing text data), unless, of course, there is already a registry entry for that file format, and that entry says that it's, say, an image file (so you wouldn't use .png, .jpg, etc.). Other than those small restrictions, you can make it whatever you want. like I said before, you could make it moose.cow if you wanted to!
Re: Custom file formats
Posted: Thu Mar 05, 2009 11:08 am
by Cole S.
So would i use C++ filestream to read chunks of the file or something??? and would there be a way to encrypt the files so you could not read them in notepad or any other text editor?
Re: Custom file formats
Posted: Thu Mar 05, 2009 11:16 am
by avansc
well thechnically tou can use any extension you want, even .bmp .jpg .mp3 .wav
anyways. if you are just goint to have something like
Code: Select all
map001
object 5
0,0,10,10,brick.jpg
10,0,10,10,brick.jpg
10,0,10,10,brick.jpg
20,0,10,10,brick.jpg
or whatever, that you read each line parse it and rebuild the level each time its loaded that fine.
another ( better ) option it to do it with binary files.
you would have lets say a level class, with all you data variables inside.
and you would just write the class to a binary file, then read the bytes from the file and store it in a level class object again.
down side to this is that your file will be non human readable, so you will have to have an editor.
nice thing about this is that its alot faster, file size is significantly smaller. parsers are practically non exsistant. easy of use. and scalability is infinate.
(so its a far better option.)
Re: Custom file formats
Posted: Thu Mar 05, 2009 12:19 pm
by Moosader
Yeah, you can have it similar to 3D model files, listing each tile like ava said:
mapname
x, y, w, h, image
x, y, w, h, image
so it would load in the information for each tile during the load.
My maps are in a grid, with the number listed representing the x coordinate of the tile (divided by 32).
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
1 1 0 0 0 0 2 0
1 0 0 0 0 2 2 2
1 1 1 1 1 1 1 1
Re: Custom file formats
Posted: Thu Mar 05, 2009 12:43 pm
by avansc
wht do so few people utilize binary files?
Re: Custom file formats
Posted: Thu Mar 05, 2009 1:13 pm
by andrew
Have a look at
this.
You should get some ideas from it even though it's specifically for isometric maps. Also it's pretty old (1999) and even though it says it's C/C++, it's really only C.
Re: Custom file formats
Posted: Thu Mar 05, 2009 1:55 pm
by wtetzner
I've decided to go with
SQLite as my level/resource file format. It's embeddable, extremely fast, and cross platform. Also, there are stand-alone applications you can use to query them, so you don't have to write your own editor before you can test your engine. And best of all, you can query it with SQL!
Re: Custom file formats
Posted: Thu Mar 05, 2009 2:05 pm
by avansc
wtetzner wrote:I've decided to go with
SQLite as my level/resource file format. It's embeddable, extremely fast, and cross platform. Also, there are stand-alone applications you can use to query them, so you don't have to write your own editor before you can test your engine. And best of all, you can query it with SQL!
as far as i know you still cant write entire objects to it... i may be wrong. but i think a self made binary file would still be beter in terms of that.