Creating levels with Tiles

Started by
3 comments, last by Lactose 7 years ago

Hello,

I am currently developing a top-down game in which I'd like to use tiles. I was wondering what would be the best way of creating levels? I saw plenty of examples when people use text files in which they put numbers describing what tile is which but is it the right way to approach this if you are planning on building something bigger? Doesn't it become tedious really fast? What would be the best way to approach this?

I tried using Tiled software for creating a tile map, but when I imported it into my application (I use C++, SDL) via Martin Grant's TMXLoader the fps would drop to an unplayable level.

If anyone could share their experiences with this and give me some advice I would be forever greatful.

Thanks

Advertisement

Huh, you only load the tiles once, before you start a level, right?

How can your FPS drop? (Not that 'fps' means much, how many milli-seconds are we talking about?)

Also, just because Tiled uses some slow format, nobody said you have to use the same format in your game too. Just copy the data from Tiled format to whatever your format is. That gives you total freedom to design your tile access code.

You can even write a convertor from Tiled to some text format with numbers, and then load the text files. Nice Tiled gui for making the levels, useful text file format to debug.

I'm using Tiled to design maps for my current project. You must be doing something wrong (exactly what you're doing wrong we can only guess) if you encounter a performance problem with this. You can try the following approach:

  • Load the TMX file contents into a buffer.
  • Use an XML parser to parse it and populate various structures that describe everything you need to know about the map (tile positions, layer information, paths to tilesets etc). I use rapidxml for parsing.
  • Locate, load and store any assets you're going to need for your current map (which generate the appropriate textures for your tilesets, but you may have other assets that you define in the map)

All of the above is done once, when you load a new map. Now, in every frame, you can traverse the map structures and render the appropriate section of the map.

the fps would drop to an unplayable level

Can it be that you're creating each tile as separate entity, and then draw every tile with a separate draw call? That's, probably, the only thing that could drop fps drastically.

removed stuff that looked offending.

The other possibility (traversing source xml file every frame) is too ridiculous to accept the thought you could do that.

Keep in mind this is the For Beginners forum.

People do silly things all the time, at all skill levels (I know that I do tons of them, at least!). A beginner loading something inside a loop instead of outside isn't something they need to feel ashamed or stupid about. It could happen, and if that's the case, it's just a matter of fixing it and learning from it -- like all bugs.

Hello to all my stalkers.

This topic is closed to new replies.

Advertisement