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

2017/5/30

getObjectsInRange help?

cococypress21 cococypress21

2017/5/30

#
Ok so I am fairly new with this method of getObjectsInRange, if someone could help out and tell me what I am doing incorrect that would be great. I am trying to make a laser disappear once it is in range of the rock, of which this code is embedded in. I keep getting a red line under "50,Laser.class" :)
Actor laser = getObjectsInRange(50,Laser.class);
        if(laser!=null)
        {
            World world;
            world = getWorld();
            damageCount++;
            world.removeObject(laser);
            
        }
Super_Hippo Super_Hippo

2017/5/30

#
The getObjectsInRange method returns a list, not just an actor. You can use a for-each to go through the list.
for (Laser laser : getObjectsInRange(50, Laser.class))
{
    damageCount++;
    getWorld().removeObject(laser);
}
You need to login to post a reply.