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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.