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

2013/11/8

how do i use atWorldEdge?

payner2013 payner2013

2013/11/8

#
HELP PLZ... ok so in the bullet class, i have set the atWorldEdge information. when i say: if (atWorldEdge()) { getWorld().removeObject(this); } my bullets still aren't being removed...why? thanks
danpost danpost

2013/11/8

#
Please show the code for the entire class. You probably placed the lines of code in the wrong place. Oh, and please use the 'code' tag below the 'Post a reply' box for inserting the code.
payner2013 payner2013

2013/11/8

#
  /**
     * Act - do whatever the Bullet wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
                public void act() 
    {
        move(10);
    }
     public void AtWorldEdge()  
    {  
        if (atWorldEdge())  
        {  
             getWorld().removeObject(this);  
        }  
    }  
                     public boolean atWorldEdge()
            
    {  
        if(getX() < 10 || getX() > getWorld().getWidth() - 10)  
            return true;  
        if(getY() < 10 || getY() > getWorld().getHeight() - 10)  
            return true;  
        else  
            return false;  
    }  
}
danpost danpost

2013/11/8

#
Remove lines 8 through 10. This will put your condition to remove when at world edge in the act method.
payner2013 payner2013

2013/11/8

#
OHHH yeah i see now... thank you very much helped alot :)
You need to login to post a reply.