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

2016/3/3

Removing object

lexboy112333 lexboy112333

2016/3/3

#
Im making a game where I want a hawk to be removed when it hits the Y axis. Can anyone help me out? Here's the code I'm looking at. public void act() { setLocation(getX() - 1, getY()); } public void move() { if (getY() <= 0) { getWorld().removeObject(this); }
ElNo ElNo

2016/3/4

#
In general your idea works well. But you have to put an method-call for your move()-method in your act()-method or it won't be executed.
    public void act() 
    { 
        setLocation(getX() - 1, getY()-1); 
        move();
    } 

    public void move() 
    { 
        if (getY() <= 0) 
        { 
            getWorld().removeObject(this); 
        }    
    }
You need to login to post a reply.