Sign in to follow this  
RojanShrestha

Loading a Map from text file

Recommended Posts

I have a framework set up for a 2D side scrolling game, with a constant background that is scrolled, and my player can now move around in the scene but now I want to place my certain sprites in certain exact locations of the game world. How do I do that.. I don't have any idea about this (please describe from basic)...

Share this post


Link to post
Share on other sites
Well, if the map is complex enough, you might want to build a simple map editor. Nothing fancy, just something to allow you to select a sprite, and place it in a 2d Grid. Next you should save the map that you have built with your editor to a text (or binary) file. For ever tile, you should write an ID (You might have different tiles; wall, lava, cloud, whatever). Then the X and Y coordinates of the tile. You might also want to add more information, for example a flag to specify whether the tile can be walked on, or might set off a certain event, which would also require an ID of it's own.

Finally when you load the game, just loop through all the tiles in your map file.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this