Hey peeps. I'm currently working on a level editor for my game. and the part im working on at the moment is like, the sprite editor for it, where you can load a bitmap from a preset directory 'Sprites' in the games directory, set the collision points and then use it. Basically, i want to make it so when you click a save button, it saves the name of the bitmap, and 2 numbers for the collision to a file... How would i do this?
I kind of also need to know how to load this information :D

The name of each bitmap is stored in an array:

std::string directories[100];

Ive never really done much saving with C++ yet, so any info would be greatly appreciated. Also, im still new-ish... So im looking for simple ways... :)



7 Years
Discussion Span
Last Post by XAaronX

You can simply use file streams to do this.. you just write the name of the desired bitmap,and the 2 numbers to a file using ofstream, then load them back using ifstream.


Can i easily save this info to a new line each save? Or should i like, make it save to a separate file each time?



of course , you can... just save the bitmaps with unique names and IDs, then when u want to read them,use ifstreams e.g

string bitmaps[2];//bitmap array
int id[2]; Bitmap ID array
ofstream fout("bitmaps.txt");
//The above code writes the first bitmap file and ID to a line, then the
//2nd bitmap and id to another line
//To read them, use ifstream to pull out ur desired choice and Id from the file

Nearly works for me perfectly, but one prob :)

When i restart the app, it overwrites the txt file :(

How can i overcome this?

Thanks peeps :D



Also, quick Q!

At the moment, i have the game menu in a few functions, and then my level editor, including read/write files, sprite edit menu etc in a while loop in another function. Im using classes, but should i also be splitting the one level editor function into many functions? If i should be, can i store them in like a header or some other format and include them up the top for less clutter?


Edited by XAaronX: n/a


If you want to append data to the file, open it with ios::app:

ofstream fout("bitmaps.txt",ios::app);

Can't really say anything about your code structure without having seen the code, but it's generally good to have short functions that fulfill a clearly defined task.


I cant edit my posts? o.o

Thx to Aranarth, worked perfectly :)

Now just want some tips to my crap code =]


This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.