Annoraaq / grid-engine

A grid based movement engine compatible with Phaser3.
https://annoraaq.github.io/grid-engine/
Apache License 2.0
235 stars 20 forks source link

Dynamic loading of tilemap, allowing player to move to new tilemap #427

Closed zbrongyaozb closed 1 year ago

zbrongyaozb commented 1 year ago

Hello everyone. I am currently trying to dynamically create and load a tilemap, and I have succeeded in doing so. However, I am unsure how to make the player move from the old map to the new map. I have looked through issue #281, but I have not found a solution.

Here is a small demo. When the player moves to the left edge, I add a new map and then call GridEngine.create(...) again. However, the player does not appear on the new map, but instead appears on the right edge of the current map.

Annoraaq commented 1 year ago

Correct me when I am wrong. It looks like when the player reaches the border of the map, you are creating a new tilemap with a new layer and you give the layer a pixel offset, so it is rendered left of the previous map.

I think that pixel offset is what causes the problem. Grid engine does not take layer pixel offsets into account. It could, but then there are problems to solve: What if several tile layers that belong to the same char layer have different offsets? Which one should propagate to the character then?

So GridEngine at the moment leaves the offset up to the user. That being said, it should not be a big issue in your case. Just use the offsetX and offsetY properties when recreating GridEngine:

https://annoraaq.github.io/grid-engine/api/interfaces/CharacterData.html#offsetX

LMK if this helps.

zbrongyaozb commented 1 year ago

Thank you so much, this is helpful for me