The given key was not present in the dictionary.

Apr 2, 2011 at 1:44 PM

On the draw method, when I call map.Draw(mapDisplayDevice, viewPort); it throws this ugly message. Could someone help me out here ? Thnx !

Coordinator
Apr 2, 2011 at 9:12 PM

Are you invoking the Map object's LoadTileSheets method during initialisation? As a reference please check the tutorial.

May 6, 2011 at 1:02 PM

I am also having this problem. I've done the tutorial four times from scratch, and map.Draw(mapDisplayDevice, viewport) always throws a KeyNotFoundException ("The given key was not present in the dictionary.") I tried making a simple 4x4 map with a single tileset, and still got the error. In addition, when I enter the code exactly as it appears in the tutorial, I get a null object error when I try to run map.LoadTileSheets(). I solved that by throwing map = new Map() into the Initialize() code, but I wonder if I am missing something.

I am using tIDE 2.0.2 and xTile engine 2.0.3 with Tutorial Content 1.2.0 on top of XNA 4.0 / Visual Studio 2010.

Coordinator
May 6, 2011 at 1:14 PM

Your call to map.LoadTileSheets() should occur after the call to map = Content.Load<Map>. The latter call should load a map instance in memory.

Can you verify the order of these calls via the debugger?

May 6, 2011 at 1:42 PM

Ah, nice catch, that explains both errors. I was calling base.Initialize() after map.LoadTileSheets(). Thanks!