Jump to content
  • Advertisement


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


Need help loading levels

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

If you intended to correct an error in the post then please contact us.

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 this post

Link to post
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 not

fprintf(TheFile, "%s", mac);

// Close file, do stuff. Later, to load the file...

fscanf(TheFile, "%d", &john); // Loads it back into john

fscanf(TheFile, "%s", mac); // Loads it back into mac

Hope this helps any, just give any questions .

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!