#### Archived

This topic is now archived and is closed to further replies.

This topic is 6932 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I''m having trouble thinking of a way to load the level for my sidescroller game. I''m not having any trouble loading the actual level, but the objects in it are giving me problems. I was thinking I could just use a simple text input file containing all the information (x,y coordinates, object type, state, etc...) for each level and than I could just loop through that upon loading each level. Is this the common way it is done? If so where can I go to get help using input files. I have had VERY little experience with them. All I have done is used some basic dos file pointers in my college programming class. So... Basically if someone could give me a real basic overview of how levels are loaded in games... I think I could figure it out from there. But I would like to know if I am on the right track. Thanks a lot. Brad Van Sickle

##### Share on other sites
This is a nice way to do it, as long as its a simple text file. It would be a good idea to make a seperate file for each level also. You said you need help with input files? How are you loading the level data now?

To answer your question, you can use two methods. For the simplest method, use fprintf and fscanf. For a more technical way, use _fread and _fwrite. I would stick with fprintf and fscanf for simple text files. just use fprintf to write data to the file, and fscanf to scan it back:
int john = 27;char mac[] = "My Name is Bill";FILE *TheFile;fopen(/*Dont remember what goes here, oops!*/);fprintf(TheFile, "%d", &john); // Not sure if you use & or notfprintf(TheFile, "%s", mac);// Close file, do stuff. Later, to load the file...fscanf(TheFile, "%d", &john); // Loads it back into johnfscanf(TheFile, "%s", mac); // Loads it back into mac

Hope this helps any, just give any questions .

• 16
• 9
• 15
• 10
• 13