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

2018/3/29

can someone help me with with the error actor not in world?

enrico1101 enrico1101

2018/3/29

#
I got the same error whether my bullet hits the edge or another object... It's driving me crazy someone help please? I have seen many answers but they don't work with my code.. kind regards,
import greenfoot.*;

/**
 * Write a description of class kogelRuimteschip here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class kogelRuimteschip extends Actor
{
    Ruimteschip ruimteschip;
    private int kogelOmhoog;
    public int alienVerwijderen;
   
    
    /**
     * hier zet je alles wat je met je kogels kan en wilt doen.
     * 
     */
    public void act() 
    {
       
        
        {kogelOmhoog();
        
        move (3);// hoe snel de kogel gaat
        
        if(getY()<10 ) getWorld().removeObject(this); //kogels moeten verdwijnen na het schieten
         
    }             
        
        if (getOneIntersectingObject(alienGroot.class) != null)
        
    {
        
        
        
        
        kogelOmhoog();
        getWorld().removeObject(getOneIntersectingObject(alienGroot.class));
        getWorld().removeObject(this);
        
        
        
        }
      
    }
 
    public void setRuimteschip (Ruimteschip g) {
        ruimteschip = g;
}
   public void kogelOmhoog()
        {
            
            setRotation (270);
            
}
}





danpost danpost

2018/3/29

#
Replace line 28 with this:
if(getY()<10 )
{
    getWorld().removeObject(this);
    return; // so no other actions are taken
}
enrico1101 enrico1101

2018/3/29

#
thanks!!! it works all fine now.
enrico1101 enrico1101

2018/3/29

#
I got one more question, im making a kind of space invaders game. I want to display a picture when the aliens did touch the spaceship (the player). how would i do this? do i need to use: if (getOneIntersectingObject(spaceShip.class) != null) ??? thanks!
Yehuda Yehuda

2018/3/29

#
If you are not going to actually use the SpaceShip and you just want to know if they inersect, then you can use:
if (isTouching(SpaceShip.class)) {
}
danpost danpost

2018/3/30

#
enrico1101 wrote...
do i need to use: if (getOneIntersectingObject(spaceShip.class) != null) ???
The answer is "No". As Yehuda pointed out, you can use what he gave; however, either is fine. Yehuda's way is easier to code while your way uses slightly less stack space and CPU time (a very insignificant savings -- really). This is because the isTouching method basically performs the exact operation that was originally asked about. That is, it returns the boolean value precisely of: getOneIntersectingObject(spaceShip.class) != null
You need to login to post a reply.