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

2013/5/14

a little trouble

Banginwithflavor Banginwithflavor

2013/5/14

#
ive run into a problem where i am trying to remove the projectile and object if the intersect however if the object hits the edges of the world it crashes. Any ideas? Scenario
   public void removeEnemies()  
   {    
       Actor enemy = getOneIntersectingObject(enemy.class);
       if(enemy != null) 
       { 
           getWorld().removeObject(enemy);
           getWorld().removeObject(this); 
       }  
   }  
davmac davmac

2013/5/14

#
"crashes"? You mean you get an exception - this, maybe?
Banginwithflavor Banginwithflavor

2013/5/14

#
Thanks! Fixed it!
SB001 SB001

2014/6/30

#
Yea i used this code to fix it:
if (getX() < 5 || getX() > getWorld().getWidth() - 5) {
            getWorld().removeObject(this);
        }
        
        else {
            if (getY() < 5 || getY() > getWorld().getHeight() - 5){
                getWorld().removeObject(this);
            }
        }
You need to login to post a reply.