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

2017/3/23

at world Edge doesn't´t work

salvo salvo

2017/3/23

#
hi my class "Projektil Gelb" a bullet should disappear on the left side of the screen (world 101,101,6) could any one help my why this doesn't´t work ? HERE IS THE CODE:
public class ProjektilGelb extends Actor
{
    
    /**
     * Act - do whatever the ProjektilGelb wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act()//ProjektilGelb tut was auch immer in der "act" Methode drin steht
    {
        moveEast();//bewegt sich nach Osten (rechts)

    }
    
     public void AtWorldEdge()  
    {  
        if (atWorldEdge())  
        {  
             getWorld().removeObject(this);  
        }  
    }  
    
    public boolean atWorldEdge()
    {  
        if(getX() < 101 || getX() > getWorld().getWidth() - 101)  
            return true;  
        else {
            return false;
        }
        
    }
    
    public void moveEast()//bewegung von ProjektilGelb wird deffiniert 
        {
        setLocation(getX()+1,getY());
    }
}
danpost danpost

2017/3/23

#
The first cell is zero and the last cell is 100, not 101. The first condition in line 24 will always be 'true'. The second part can just compare with zero.
salvo salvo

2017/3/24

#
Thanks LEGEND YOU ARE THE LEGEND OF GREENFOOT
You need to login to post a reply.