-1

I am trying to use a destroy function in a game I am developing to create a platform that is destroyed upon contact with the player. However, when I run the game and touch the block, the game crashes. The block also destroys everything below it.

I tried using different variables to execute the function but the same problem occurred I tried many different methods, yielding the same results.

Here is my current code:

const configBlockEvents = (block) => {
  block.on("collide", (data) => {
    const __player = data[1];
    const __block = data[0];
    if(__block.t === "+") {
      nextLevel = true;
    }
    if(__block.t === "3") {
     destroy(__block)
    }
Barmar
  • 741,623
  • 53
  • 500
  • 612

1 Answers1

0

The Kaboom website has docs and demos for destroy()
https://kaboomjs.com/#destroy

// when the player collides with a game object with tag "fruit", remove the game object
player.onCollide("fruit", (fruit) => {
    destroy(fruit)
})

See the "RPG" demo
https://kaboomjs.com/play?demo=rpg

It looks like you're putting the collider on 'block' instead of your player.
And it might be better to use onCollide().

It's best to post your full code or link to it