2
\$\begingroup\$

I recently started learning XNA and after getting annoyed with creating individuals rectangles each time I wanted to add something I went with TiledLib so I could more easily create levels using the Tiled map editor. My problem is, though, I have no idea how to check for collision using TiledLib. There is very little documentation on it and where people have solved the problem it seems like the code they provide is outdated.

For those who do not know TiledLib: https://bitbucket.org/nickgravelyn/tiledlib

I'm using mostly the code that comes in the demo (such as Map.cs/MapProcessor.cs) because I don't know too much how it works, but it does the job.

I've heard to detect for collision I should use a seperate layer that contains all the tiles I want to collide with, but aside from updating the map to accomdate that I don't know how to actually check for that in my code and make those tiles collide with things. Also, attempting to add a layer to my tile map and then running my game provides this error:

Error   1   Building content threw ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
   at System.ThrowHelper.ThrowArgumentOutOfRangeException()
   at System.Collections.Generic.List`1.get_Item(Int32 index)
   at PlatformerContentPipeline.MapProcessor.Process(MapContent input, ContentProcessorContext context) in e:\Platformer\Platformer\PlatformerContentPipeline\MapProcessor.cs:line 94
   at Microsoft.Xna.Framework.Content.Pipeline.ContentProcessor`2.Microsoft.Xna.Framework.Content.Pipeline.IContentProcessor.Process(Object input, ContentProcessorContext context)
   at Microsoft.Xna.Framework.Content.Pipeline.BuildCoordinator.BuildAssetWorker(BuildItem item)
   at Microsoft.Xna.Framework.Content.Pipeline.BuildCoordinator.BuildAsset(BuildItem item)
   at Microsoft.Xna.Framework.Content.Pipeline.BuildCoordinator.RunTheBuild()
   at Microsoft.Xna.Framework.Content.Pipeline.Tasks.BuildContent.RemoteProxy.RunTheBuild(BuildCoordinatorSettings settings, TimestampCache timestampCache, ITaskItem[] sourceAssets, String[]& outputContent, String[]& rebuiltContent, String[]& intermediates, Dictionary`2& dependencyTimestamps, KeyValuePair`2[]& warnings)   e:\Platformer\Platformer\Platformer\PlatformerContent\level1.tmx    Platformer

I'm at a loss at what to do. If anyone could help me with this, or perhaps let me know of a more updated and more well documented 2D engine for C#/XNA, that would be great.

\$\endgroup\$
1
  • \$\begingroup\$ When you say "attempting to add a layer to my tile map", do you mean just adding a new layer in Tiled map editor and not doing anything to the code? \$\endgroup\$ Commented Jan 11, 2013 at 15:04

1 Answer 1

1
\$\begingroup\$

TiledLib will not do collision for you it only converts tmx files into a set of in memory objects that you can use.

I had the same problem as you when using the MapProcessor in the TiledLib example. According to the following forum

The demo code expects that maps do not have null or missing tiles.

You can identify an empty tile by the tileId. The call TiledHelpers.DecodeTileID will return a tileId of 0 if that location has no tile. In this case you should not attempt to load the tile at that index.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .