question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ct.rooms.merge prefab multiple times breaks ct.place.tile

See original GitHub issue

Describe 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

  1. Create a Prefab room
  2. Add a tile layer with depth -5, set a tileset image and draw some blocking tiles.
  3. 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 its tiles array (for collision detection)
  4. Repeat step 3 with different offsets, to give two copies of the same prefab in your room
  5. Any calls to ct.place.tile fails when over the tiles placed in point 3.

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

2020-05-17 08_41_27-ct js game — ct js

Second control: blocks player

2020-05-17 08_41_57-ct js game — ct js

Test: Merging the Second prefab in again (as Third):

Test: Second does not block the player any more

2020-05-17 08_43_05-ct js game — ct js

Test: Third does block

2020-05-17 08_43_16-ct js game — ct js

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:closed
  • Created 3 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
CosmoMyzrailGorynychcommented, Jun 23, 2020

I also currently recommend shifting visual tiles instead of moving their tileset until #128 is settled:

// Insert single prefab twice -- works
var data = ct.rooms.merge('Single Prefab');
for (const copy of data.tileLayers) {
    // offset the layer -- for drawing position
    copy.children.forEach((t) => {
        t.x += 64;
        t.y += 128;
    });
    // offset the tiles -- for collisions
    copy.tiles.forEach((t) => {
        t.x += 64;
        t.y += 128;
    });
}
0reactions
wesleywernercommented, Jul 2, 2020

Excellent, thanks for all your effort on this wonderful project, Cosmo!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Prefab Houses in Connecticut
Search 16 Connecticut Prefab House to find the best for your project. See the top reviewed local in Connecticut on Houzz.
Read more >
Sqf - River Thames Conditions - Environment Agency - GOV.UK
Silent brass trompeta, Being with a man for the first time, Concacaf final ... 1738 connecticut ave nw, Hcl l1114 laptop drivers, Ampaoid,...
Read more >
Concrete Vapor Barriers: Everything You Need to Know
Capillary breaks do a good job of stopping water in its liquid state from reaching a slab. However, they can't stop water in...
Read more >
2022 Cost to Remodel a Bathroom
The average cost to remodel a bathroom is about $5500 (Full remodel of a 45 sq.ft. bathroom with a separate tub and shower)....
Read more >
Remembering Connecticut residents who died after ...
John Roberts had two engineering degrees and worked at Pratt & Whitney for more than 40 years, his obituary said. "Always the funniest...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found