Reputation: 86
I have the following map created with the Tiled software and I want to make the chest functional. Actually, I want to know when the player and the chest overlap but even searching for hours I can't find a solution.
I am using ARCADE physics. I tried using object layers but nothing works...
Upvotes: 0
Views: 117
Reputation: 508
One very simple solution is to place an object over the chest in a seperate object layer. When you are loading the map into your game, check for all objects in that layer and store it somewhere (e.g. in a List)
During your game you can easily check if your player overlaps one of your chests.
Hint: you can give your chest-objects an id and other parameters to define their behavior.
An implementation looks something like this:
Your objects appear in your .tmx
<objectgroup name="Container" offsetx="0" offsety="2">
<object id="148" name="Chest1" x="72" y="3654">
<properties>
<property name="state" value="chest_closed"/>
<property name="epic_Items" value="false"/>
...
</properties>
</object>
</objectgroup>
Now just parse them into your game logic
List<ItemContainer> lootableContainers = new List<ItemContainer>();
foreach (var o in curMap.ObjectGroups["Container"].Objects)
lootableContainers.Add(new ItemContainer([o.params]));
Upvotes: 1