How to use getCharactersAt #361
-
Hi everyone, I need to check if there is a player in determined position What I found is the funcion getCharactersAt which receives 2 parameters: position (x, y) and layer (string). The problem is that I always receive an empty array. Here is the test code:
Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I think in your case the problem is that you omit the Now that I see it, I must say that I can understand the confusion here. It is not very intuitive that the char layer is also changed if you do not pass it. I think a reason for this was compatibility for tilemaps without char layers. If no char layers are specified in a tile map, the uppermost layer that does not have the One alternative would be to change setPosition in a way, that it does not change the char layer at all, if it is set to undefined. However, I will update the docs, so that it is explicit that the layer |
Beta Was this translation helpful? Give feedback.
I think in your case the problem is that you omit the
charLayer
argument ofsetPosition
. Therefore it defaults toundefined
. So you position the character to charLayerundefined
.Change it to
this.gridEngine.setPosition("player", { x: 50, y: 50 }, "charLayer");
and it should work.
Now that I see it, I must say that I can understand the confusion here. It is not very intuitive that the char layer is also changed if you do not pass it.
I think a reason for this was compatibility for tilemaps without char layers. If no char layers are specified in a tile map, the uppermost layer that does not have the
ge_alwaysTop
property is selected as the default char layer, calledundefined
.And it is an…