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

2019/10/31

How do I remove another actor.

AVH AVH

2019/10/31

#
I'm trying to kill an orc, by using key is down "space" to remove an orc and use an image when space is clicked. But it is not working.
 public void checkSpace() 
    {
        Orc orc = (Orc) getOneIntersectingObject(Orc.class);
        if (Greenfoot.isKeyDown("space"))
        {   
            if (orc != null) {
                getWorld().removeObject(this);
            }
            setImage(M1); 
            
        }
       
    }
danpost danpost

2019/10/31

#
AVH wrote...
I'm trying to kill an orc, by using key is down "space" to remove an orc and use an image when space is clicked. But it is not working.<< ,<< Code Omitted >>
If the orc is an intersecting object, then line 7 removes the wrong actor.
You need to login to post a reply.