Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

HOW CAN I DESTROY AN SPRITE?


ismaPC95
 Share

Recommended Posts

npcplayerUno = this.physics.add.sprite(800, 450, 'enemy').setScale(0.2);
npcplayerUno.setBounce(0.1);
npcplayerUno.setCollideWorldBounds(true);
 
this.physics.add.collider(player, npcplayerUno, killEnemy, null, this);

 

//TRY TO DO AN IA
//pasar otra variable por parametro que sea la del enemigo en cuestion, por si se realiza con varios
if(npcplayerUno!=undefined){
if(player.body.position.x<npcplayerUno.body.position.x){
setTimeout(function(){/*npcplayerUno.body.position.x=-1;*/
npcplayerUno.setVelocityX(-95);
npcplayerUno.anims.play('moveEnemyLeft', true);
},500);
}else if(player.body.position.x>npcplayerUno.body.position.x){
setTimeout(function(){/*npcplayerUno.body.position.x=+1;*/
npcplayerUno.setVelocityX(95);
npcplayerUno.anims.play('moveEnemyRight', true);
},500);
}else{
npcplayerUno.setVelocityX(0);
npcplayerUno.anims.stop();
}
}
 
function killEnemy(player, npcplayerUno){
if(npcplayerUno.body.touching.up && player.body.touching.down){
player.setVelocityY(-350);
npcplayerUno.setVelocityX(0);
npcplayerUno.scaleY=0.12;
//npcplayerUno.destroy();
}
}

phaser.PNG

Link to comment
Share on other sites

if (npcplayerUno.exists === true) {
npcplayerUno.setVelocityX(95);
// Do your stuff here.
// If it doesn't have an exists property create your own and change it to false on destroy event.
}

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...