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

2020/4/23

Changing Image from an Actor

greenfish greenfish

2020/4/23

#
If my projectile hits the target, he needs to change his image.
1
2
3
4
5
Player rakete = new Player();
if(isTouching(Player.class)){
rakete.setImage("explosion.jpg");
getWorld().showText("IHRE RAKETE WURDE ZERSTÖRT.", getWorld().getWidth()/2, getWorld().getHeight()/2);
Greenfoot.stop();
but its not working quite well.. This code is in my projectile class.
danpost danpost

2020/4/23

#
Changing the state (image, in this case) of one Player object does not do the same to all Player instances. You need to change the image of the one player already in the world (not create a different Player object and change its image; as well, that one was never put in the world, so its image is immaterial). Replace your first two lines with this:
1
2
if (isTouching(Player.class)){
    Actor rakete = getOneIntersectingObject(Player.class);
You need to login to post a reply.