I'm writing some games with phaser and I'm facing a problem with the method sprite.kill().
Sometimes when I call sprite.kill() Phaser seems to destroy the body for collisions/overlapping but the visual element(image and draggable object) still on screen.
I've set the overlapping method for all my objects through a foreach:
garbList.forEach(function(g) {
trashList.forEach(function(t) {
game.physics.arcade.overlap(g.sprite, t.sprite, garbHitTrash);
});
});
I have a garbageList and a trashList and they have a method for overlaping called garbHitTrash.
When garbHitTrash is called it just "throws the garbage on the trash" destroying its sprite and popping it from then garbList.
function garbHitTrash(garb, trash) {
if(garb.trash === trash.type) {
result['acertos']++;
} else {
result['erros']++;
}
garb.kill();
popGarbage(garb)
console.log('garbList.length ' + garbList.length);
}