39 kill - JcerelusDev/CanvasGameJs GitHub Wiki

What is the kill method ?

The kill method is used to remove one item from an array of items.

For example if a bullet touch a specific enemy you can remove that enemy & the bullet in the scene by using The kill method. The kill method has 2 arguments :

1.- first arg for the array of objects.

2.- 2nd arg for the specific index of one object.

Example :

for(var i = 0; i < enemies.length; i++){

for(var j = 0; j < player.bullet.length; j++){

if(isCollide(enemies[i],player.bullet[j])){
kill(enemies,i);
kill(player.bullet,j);

}


}

That code above is an example you can use it as you wish once you follow the correct rule.

Kill(your array of object,index);