The docs for tilemap.createFromObjects() say this:
The
gid
argument is matched against:
- For a tile object, the tile identifier (
gid
); or- The object’s unique ID (
id
); or- The object’s
name
(a string)
I have a use case where it would be ideal to locate map objects by their id, not by their name or GID. However, when I try to do this:
this.endpoints = this.map.objects.endpoints;
this.ledgesGroup.endsgroup = this.game.add.group(this.ledgesGroup, 'endsgroup');
this.endpoints.forEach((end)=>{
this.end = this.map.createFromObjects('endpoints', end.id, 'utility', 'point', true, false, this.ledgesGroup.endsgroup);
});
I get nothing. Console logging each this.end returns undefined, and logging each end in the forEach reveals that Phaser is receiving all of the object’s properties EXCEPT the object id:
{
1. height: 0
2. name: "end"
3. rectangle: true
4. rotation: 0
5. type: "end"
6. visible: true
7. width: 0
8. x: 983
9. y: 832
}
Logging this.endpoints shows the same thing: Phaser isn’t even seeing the object ids, even though the json has them:
{
"height":0,
"id":37, <=== THIS!
"name":"end",
"point":true,
"rotation":0,
"type":"end",
"visible":true,
"width":0,
"x":624,
"y":592
},
Am I missing something? Am I making a mistake somewhere? Are the docs wrong? I’m using phaser-ce@2.18.0 and Tiled 1.7, and exporting my Tiled json files under the option of JSON map files [Tiled 1.1]. I tried exporting the tilemap with the regular JSON option and the result was the same, plus a console warning advising me to switch to the Tiled 1.1 exporter.
EDIT: if it makes any difference, the endpoint objects are Point objects in Tiled.