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

2022/5/1

isAtEdge not working

ADAM68801 ADAM68801

2022/5/1

#
Hi, I dont know why but method isAtEdge is not working and there is error every time. Can someone please help?
public class Reload extends Actor
{
    
    /**
     * Act - do whatever the Reload wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
     public static int pocet = 0;
    public Reload()
    {
        GreenfootImage image = getImage();
        image.scale(image.getWidth() +25, image.getHeight() + 25);
        setImage(image);
    }
    public void act()
    {
    if (Coin.type == 1)
    {
        lod();
    }
    if (Coin.type == 2)
    {
        lod2();
    }
    if (Coin.type == 3)
    {
        lod3();
    }
    if (isAtEdge())
    {
        getWorld().removeObject(this);
    }
   
    move(-2);
    
    }
    public void delete()
    {
        if(isAtEdge())
         {
             getWorld().removeObject(this);
         }
    }
    public void lod()
    {
         if (isTouching(Lod.class))
    {
      getWorld().removeObject(this); 
     
      
     }
    }
    public void lod2()
    {
        if (isTouching(Lod2.class))
    {
      getWorld().removeObject(this); 
       
      
     }
    }
    public void lod3()
    {
        if (isTouching(Lod3.class))
    {
      getWorld().removeObject(this); 
        
     
     }
    }
    
}
Super_Hippo Super_Hippo

2022/5/1

#
When you remove the Actor from the World, you must not call any more methods which require the Actor to be in a World.
danpost danpost

2022/5/1

#
Super_Hippo wrote...
When you remove the Actor from the World, you must not call any more methods which require the Actor to be in a World.
In act method, move if (isAtEdge()) block to the beginning. After that, in act method, modify all if statements except the first to be else if statements.
ADAM68801 ADAM68801

2022/5/2

#
Thanks, it worked
You need to login to post a reply.