-1

I have tried to make a collision with my player and my map but he don't work My code: http://pastebin.com/yWRuQkEr

Its a picture of the error: the image.

I'm french and VS don't translate all of the messages.

The Key its absent of the dictionnary.

Dovydas Šopa
  • 2,282
  • 8
  • 26
  • 34
  • Just show the relevant code. You get the error where? And what is the error? Google does a good job at translating error messages, btw. – waka Feb 28 '17 at 12:55
  • You have the error in the image and the code is _map.ObjectGroups["Collision"].Objects its in the foreach at line 79 – TheYoungGeek 43 Feb 28 '17 at 13:24

1 Answers1

0

I am using TiledSharp for a quite long time now. This error usually appears if your created map does not contain such objectgroup.

Check your .tmx file if the objectgroup actually exist. it looks like this:

<objectgroup name="Obstacles">
  <object id="1" x="35" y="39" width="24" height="20"/>
</objectgroup>

the code for this looks like that (in my case):

foreach (var o in curMap.ObjectGroups["Obstacles"].Objects)
    collisionObjects.Add(new Rectangle((int)o.X, (int)o.Y, (int)o.Width, (int)o.Height));

Be aware that the name is case sensitive. Objectgroups are usually at the end of the .tmx file

Pavel Slesinger
  • 498
  • 3
  • 12