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

2021/4/14

How do I make actor disappear after touching another actor.

ExistingProof ExistingProof

2021/4/14

#
I have one, I think, easy to solve problem, just syntax problem. I want to make Clouds disappear after touching this actor. The error shows - "cannot find symbol - variable Cloud". Even "Cloud.class" isnt working. Thanks a lot^^
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Lietadlo here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Lietadlo extends Actor
{
    /**
     * Act - do whatever the Lietadlo wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        posuvanie();
        checkIfPlaneisTouchingCloud();
        
    }    
    
    public void posuvanie()
    {
        if(Greenfoot.isKeyDown("d"))
         setLocation(getX()+1, getY());
        if(Greenfoot.isKeyDown("a"))
         setLocation(getX()-1, getY());
        if(Greenfoot.isKeyDown("w"))
         setLocation(getX(), getY()-1);
        if(Greenfoot.isKeyDown("s"))
         setLocation(getX(), getY()+1);
        
        
 
         
         
    }
     private void checkIfPlaneisTouchingCloud(){

        if(isTouching(Cloud.class)){
            setImage("game_over.png");
            removeObject(Cloud);
            Greenfoot.stop(); 
            
        }
        }
    
    
}
danpost danpost

2021/4/14

#
The only Actor class method that can remove an object from the world is the removeTouching(Class) method.
You need to login to post a reply.