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

2023/1/15

Sending Information from one Actor to another

Mordanto Mordanto

2023/1/15

#
I want to create an explosion by changing an image in the missile, but the "Gegner" checks whether the missile has hit him or not. I have done this because the Gegner's hp is deducted for this. But now I have to somehow tell the rocket to change its magic. Below the code from the Gegner if (isTouching(Rocket.class)){ hp=hp-50; /** here I would like to tell the rocket to change its image deathcount = (deathcount+1)%20; if (deathcount == 0){ removeTouching(Rocket.class); } }
danpost danpost

2023/1/16

#
Mordanto wrote...
I want to create an explosion by changing an image in the missile, but the "Gegner" checks whether the missile has hit him or not. I have done this because the Gegner's hp is deducted for this. But now I have to somehow tell the rocket to change its magic. << Code Omitted >>
The following will call a public method that you can put in the Rocket class:
((Rocket)getOneIntersectingObject(Rocket.class)).changeImage();
You need to login to post a reply.