This site requires JavaScript, please enable it in your browser!
Greenfoot back
Gautham
Gautham wrote ...

2018/8/24

How to make a enemy disappear

Gautham Gautham

2018/8/24

#
I need to know the code to make 1 enemy disappear or killed
Super_Hippo Super_Hippo

2018/8/24

#
It depends on the condition. Examples:
//bullit hits enemy
//in act
removeTouching(Enemy.class);
//from world -- with reference
private Enemy enemy = new Enemy();
//adding
addObject(enemy, 100, 100);
//removing
removeObject(enemy);
//from world -- without reference
//remove all enemies
removeObjects(getObjects(Enemy.class));
//remove one, maybe have to check if there is an enemy first
removeObject(getObjects(Enemy.class).get(0));
//from the enemy class itself, for example when his life reached 0
getWorld().removeObject(this);
You need to login to post a reply.