I have a functionality of creating me NPCs from an object layers inside the create function, which it looks like this:
const npcs = this.physics.add.group();
if (map.getObjectLayer('npcLayer')) {
map.getObjectLayer('npcLayer')['objects'].forEach(object => {
const obj = npcs.create(object.x + 8, object.y + 8, 'testNpc');
obj.properties = object.properties; // assigning properties here
obj.body.height = object.height;
obj.body.width = object.width;
obj.body.immovable = true;
obj.setSize(14, 12).setOffset(1, 10).setDepth(obj.y);
// console log here shows them
});
}
...
this.physics.add.collider(player, npcs, npcAction); // inside the npcAction function they're gone
Like commented in the last line the assigned properties are gone for some reason. How ever I have a same procedure for the loading zones, where this works! The code looks like this:
const loadingZones = this.physics.add.staticGroup();
map.getObjectLayer('loadingZoneLayer')['objects'].forEach(object => {
let xValue = object.x + 8;
let yValue = object.y + 8;
let height = object.height;
let width = object.width;
switch (object.properties[MapProperties.FACING_IN].value) {
...
}
const obj = loadingZones.create(xValue, yValue, 'loadingZone');
obj.properties = object.properties;
obj.body.height = height;
obj.body.width = width;
});
...
this.physics.add.overlap(player, loadingZones, load);
and this works. Inside the load funtion the given object has the assigned properties.
After trying for a day and a half and googleing for answers I’m out of ideas why it’s not working for the npcLayer.
