Alternative to using stream reader to load in a 2D levels information

Started by
-1 comments, last by DriveByBaptism 13 years ago
I was wondering if you guys know any good ways (and in turn tutorials/source code) for loading in 2D levels for a platformer game.

At the moment I'm using streamreader to read in a text file of integers and the code is quite big and a horrid to refactors. At the moment, how I'm doing things is as follows so you get a feel of what I mean:
using (StreamReader sr = new StreamReader(LevelName))
{
//Starting positions for tiles
int x = 0;
int y = 0;

while (!sr.EndOfStream)
{
string line = sr.ReadLine();
string[] elements = line.Split(',');

foreach (string e in elements)
{
//Use a char to make the text file easier to read as opposed to intergers
int t = int.Parse(e);

//load player sprite
if (t == 1)
{
playerSprite = new Player();
playerSprite.Position = new Vector2(x, y);
//character.Position = new Vector2(playerSprite.Position.X, playerSprite.Position.Y);
playerSprite.Load(@"Sprites/transpbox", Content, simulator);//default image for the player
playerSprite.Body.Mass = 10;
playerSprite.IsStatic = false;
tiles.Add(playerSprite);//added to the tile array
playerSprite.Geom.OnCollision += OnCollision;//fired when in contact
}


Now imagine that for each of your games assets. It's gets ungodly quickly. So I'm just wondering if you guys have any good/quick alternatives.

This topic is closed to new replies.

Advertisement