ct.rooms.merge prefab multiple times breaks ct.place.tile
See original GitHub issueDescribe the bug
Calling ct.rooms.merge
to load parts of a room from prefabs works only if you load the prefab once. When loading the same prefab a second (or more) times into the same room, then the tileLayer.tiles instance for subsequent calls points to the first instance – thus updating the tiles array positions clobbers the first insance’s tiles, breaking any future calls to ct.place.tile
.
For tile-based games where there a lots of tiles, you don’t want to create a Type for each tile that can block the player. Thus drawing all blocking tiles to a layer with a depth of -5
and calling ct.place.tile
to test for collisions is the most optimal solution.
To Reproduce
- Create a Prefab room
- Add a tile layer with depth
-5
, set a tileset image and draw some blocking tiles. - Create a Main room and in the On Create Room Event load the prefab with
ct.rooms.merge
, applying offsets to the tileLayer (for drawing position) and for itstiles
array (for collision detection) - Repeat step
3
with different offsets, to give two copies of the same prefab in your room - Any calls to
ct.place.tile
fails when over the tiles placed in point3
.
Expected behavior
Each subsequent call to ct.rooms.merge
should give the copy of tileLayer
its own tiles
object array, allowing you to merge the same prefab more than once in the current room.
Screenshots
Test control: First and Second blocks merged from TWO different prefabs:
First control: blocks player
Second control: blocks player
Test: Merging the Second prefab in again (as Third):
Test: Second does not block the player any more
Test: Third does block
Example project roommergebugsample.zip
- Open Room “Main Level” and enter Room Events.
Versions:
- OS: Windows 10 x64
- ct.js version 1.3.1
Thanks
I want to say thanks to everyone involved in this project, it is a lovely tool 😃
Issue Analytics
- State:
- Created 3 years ago
- Comments:7
I also currently recommend shifting visual tiles instead of moving their tileset until #128 is settled:
Excellent, thanks for all your effort on this wonderful project, Cosmo!