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

2016/4/15

Switching images

RedBird420 RedBird420

2016/4/15

#
I'm trying to create a game where there are hungry elephants walking towards a stick man. The stick man's job is to shot peanuts at the elephants and feed them so that he doesn't get trampled. How can I do this so that when the elephant is hit by the peanut it switches to the second image?
danpost danpost

2016/4/15

#
In the act method of the class of the elephant:
if (isTouching(Peanut.class))
{
    setImage(<?  whatever ?>);
    removeTouching(Peanut.class); // optional - to remove the peanut from the world
}
RedBird420 RedBird420

2016/4/16

#
I'll try it out. Thanks! I
You need to login to post a reply.