In my code I am trying to call .destroy(); on my player in a collision function but everytime I try to destroy my player or do anything like that in any of my functions the game freezes/crashes. Any ideas/help greatly appreciated. Also sorry if the code looks a bit messy I couldnt figure out how to properly upload the code snippit.
function create() {
cursors = this.input.keyboard.createCursorKeys();
//player
player = this.physics.add.sprite(200, 200, ‘player’);
//Enemy
spikes = this.physics.add.group();
//bullets
bullets = this.physics.add.group({
allowGravity: false,
});
//when bullet touches spikes destroy that spike
this.physics.add.overlap(bullets, spikes, hitSpike, null, this);
//when player touches spike kill the spike
this.physics.add.overlap(player, spikes, killSpike, null, this);
}
//bullet destroy spike
function hitSpike (bullet, spike)
{
var crystal = crystals.create(spike.x, spike.y, ‘crystal’);
crystal.setScale(1.25)
spike.destroy();
}
//kill player
function killSpike (player, spike) {
player.destroy();
}