Error using xTile with a state manager

Jun 4, 2013 at 1:38 AM

I tried using xTile with my StateManager but I can't get it to work properly. I'm having an error on the map.Draw(StateManager.mapDisplayDevice, viewport); saying :
The given key was not present in the dictionary.

I created the XNADisplayDevice in my StateManager Initialize() similar to what was done in the example and I,m trying to use it in my GameplayState. I can see that the displayDevice is not null and viewport is also not null.

Any ideas??

Jun 4, 2013 at 8:17 AM
Did you call
before attempting to draw?
Jun 4, 2013 at 1:25 PM

I did exactly what was shown in the xTile tutorial but inside my gameplayState (the tutorial worked perfectly when I tried it as a stand alone game)...

What is the dictionnary it's talking about!? Is it your TileSheets ReadOnlyCollection<TileSheet>? Cause I haven't found any Dictionnary...

Plus I've placed xTile.dll and xTilePipeline in my game library instead of directly in my game folder, but rest assure that i did all the referencing so it's shall not be a problem.

The only strange thing i noticed is that it asked me to CREATE a new instance of map so in my constructor I did a map = new Map();
That would be the only major difference with the tutorial I can think of.

P.S. The map file is compiled correctly and the paths inside for the TileSheet are corrects.
Jun 4, 2013 at 2:51 PM
Do you have an exception trace I can look at?
Jun 4, 2013 at 4:35 PM
Edited Jun 4, 2013 at 4:36 PM
well i kind of solve the problem...

The problem was the call to LoadTileSheet.

If I do the call in my GameplayState.LoadContent() I end up with an empty DisplayDevice.m_tileSheetTextures.

Instead i make the call in GameplayState.Draw() and now it's working but it's no where near elegant.

I tried to move it back in GameplayState.LoadContent() and initialize the DisplayDevice in StateManager.LoadContent() instead of Initialize() but it give me the same message error as before.
Jun 5, 2013 at 12:08 AM
Ok i fixed evrything...

the map.LoadTileSheet was placed before the map = Content.Load... so that's why it wasn't able to load the tilesheet... a stupid mistake...

thanks for your support!!
Jun 5, 2013 at 7:12 AM
We all have our derp moments :) Glad you solved it!