Ask coding questions

← Back to all posts
how do you remove a sprite in kaboom.js
mrslep (30)

look at the title above
ya

Answered by RoBlockHead (433) [earned 5 cycles]
View Answer
Comments
hotnewtop
RoBlockHead (433)

destroy(whatever variable you assigned the component to) so for exemple:

// adds the sprite 
const comp = add([sprite(“thisSprite”)]);
// destroys the sprite
destroy(comp);

the documentation on kaboomjs.com outlines this, but sometimes it’s difficult to read documentation :)

Coder100 (17091)
let sprite = add([
  sprite("img")
]);

destroy(sprite);

we don't remove sprites in kaboom, we destroy them (preferably with bombs)

mrslep (30)

@Coder100 i was going to say for example

if cat.collide("cactus")
destroy(cat);