Home > Gruedorf > Maps and more sloped surfaces

Maps and more sloped surfaces

December 2nd, 2008

As a quick way of getting something that resembles content into the game, I wrote a simple loader for for Tiled’s XML map format. It was pretty straightforward, but I did discover that for whatever reason, XNA’s built in XML loader for the Content Pipeline doesn’t support XML files with a DTD attached. Also, for some reason, it can take up to two seconds to read the map in from XML - I think there’s some sort of bug in XmlReader related to really long lines (the tiled map I’m using has a 50000-character line of base64 text in it) that’s causing it to randomly perform slower. At least it works.

Regardless, I put a simple map together and made some basic tiles, and got it loading into the game. Then I had to figure out how to map collision geometry to the tiles.

The first approach I took was using Tiled’s metadata to attach ’shape’ information to each tile. It worked, more or less, but I ran into weird issues with there being gaps between the edges of the tiles that the player could get stuck on or fall through, so for now, I abandoned that method. The algorithms I’m using to do motion and collision detection work best with large shapes to collide against, instead of individual tiles, since they operate on pairs of polygons or on single polygons. I think to properly collide against tiles directly, I’ll need a way to build large collision polygons from groups of tiles automatically.

One of the things I quickly discovered is that having lots of sloped surfaces brought out a few bugs - for example, small sloped surfaces with a very steep slope didn’t work right, with the player getting stuck on the left and right edges. The solution to this actually turned out to be pretty simple - instead of determining what the player is standing on, I switched to doing a ’standing’ check at multiple locations on the player’s X axis - the left side, the right side, and the middle. I use all three of those checks to compute ’standing’ Y positions, and take the minimum one. This seems to fix the algorithm for all of the test cases I have in this map - he moves up and down sloped surfaces just about right and can cross between surfaces without any glitches.

On an unrelated note, SpriteBatch is pretty damn nice. It’s fast, it’s simple, and it does exactly what you’d want it to do. A lot of people building rendering and game dev libraries tend to lean towards ‘heavy’ tools, like a first-class Sprite object with lots of properties and methods, but the XNA guys decided to let you do everything but the rendering, and I think that was definitely the right choice.

Future milestones:

  • Loading collision geometry from a file
  • Saving and loading the player’s game, along with the necessary integration for it to work right on the 360
  • Background content loading
  • Some basic AI creatures to fight

Gruedorf , , , , , ,

  1. No comments yet.
  1. No trackbacks yet.