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

2013/2/20

Help with changing Images.

shayanaijaz shayanaijaz

2013/2/20

#
Hi, I am new to greenfoot. I am making a zombie game with 3 characters. One is a weak zombie, another is a strong zombie and the last is the hunter. The hunter kills the weak zombies but is eaten by the strong zombie. When the hunter kills the zombie I want to change the zombie's image to blood and i am having problems with that as i have no idea what to do.
danpost danpost

2013/2/20

#
To replace one actor with another: (this is how it would be coded in the weak zombie class)
getWorld().addObject(new Blood(), getX(), getY());
getWorld().removeObject(this);
If there is more code in the method, add a 'return;' statement after this code. Also, if this code is in a method that is called from the 'act' method, and there is more code after the call to this method, add 'if (getWorld() == null) return;' after the call in the 'act' method.
danpost danpost

2013/2/20

#
In the hunter zombie class, it would be a bit different:
Actor weakOne = getOneIntersectingObject(Zombie.class);
getWorld().addObject(new Blood(), weakOne.getX(), weakOne.getY());
getWorld().removeObject(weakOne);
You need to login to post a reply.