Well how are you doing it?
Anyways i just save binary data using structs.
This is my Object struct just handles basic stuff for now but can easily expanded in the future
- Code: Select all
struct OBJECT
{
int ox;
int oy;
int oAnim;
int flag;
};
Here is the save and load functions for writing and reading the data
- Code: Select all
void loadLvl(char* LoadSaveTag)
{
int j;
struct OBJECT o[LevelSize];
FILE * lvlF;
lvlF=fopen(LoadSaveTag, "rb");
if(lvlF)
{
fread(o, sizeof(o), 1, lvlF);
for(j=0; j<LevelSize-1; j++)
{
if(o[j].flag==1)
{
CreateActor("Object", "ObjectSet", "(none)", "(none)", 0, 0, true);
object=getclone2("Object", j);
object->x=o[j].ox;
object->y=o[j].oy;
object->animpos=o[j].oAnim;
}
else
break;
}
}
free(o);
fclose(lvlF);
}
void saveLvl(char* LoadSaveTag)
{
int j;
struct OBJECT o[LevelSize];
FILE * lvlF;
lvlF=fopen(LoadSaveTag, "wb");
if(lvlF)
{
for(j=0; j<oACTORCOUNT; j++)
{
object=getclone2("Object", j);
o[j].ox=object->x;
o[j].oy=object->y;
o[j].oAnim=object->animpos;
o[j].flag=1;
}
fwrite(o, sizeof(o), 1, lvlF);
}
free(o);
fclose(lvlF);
}
I just grab the x y and animpos from the objects when i open the save and load menu in my map maker, i store them in the struct and save them to an external file so i can read back later.
If you have trouble understanding let me know!