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

2014/2/5

remove only one object not all

BGY12C BGY12C

2014/2/5

#
Hey, I want that the balls are disappearing when they touch an object. So now it works but all balls disappears when the first ball touch an object. But I want that only the one disappears that touchs the object. Ball:
    public void act() 
    {
        setLocation(getX() + geschwindigkeit, getY());
        Actor ball = this.getOneObjectAtOffset(0, 0, Ball.class);
        if ((getX() == getWorld().getWidth()-1) || (getX() == getWorld().getWidth()+1) || (getX() == getWorld().getHeight()-1) || (getX() == getWorld().getHeight()+1)) {
            getWorld().removeObjects(getWorld().getObjects(Ball.class));
        }   
    }
erdelf erdelf

2014/2/5

#
change line 6 to
getWorld().removeObject(this);
You need to login to post a reply.