ismaPC95

HOW CAN I DESTROY AN SPRITE?

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

Share this post


Link to post
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.
}

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.