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

2014/1/21

Getting number of objects in range?

DSP512 DSP512

2014/1/21

#
Is it possible to get the number of objects that are in a certain range, so I could use the method getWorld().removeObjects(getObjectsInRange(int radius, Class.cls)) to remove the Objects and then multiply the score with the number of objects in this range? I already read in the Greenfoot API that the World already has a method called numberOfObjects(), but it only works for the whole world, it can't be limited to a smaller range.
davmac davmac

2014/1/21

#
getObjectsInRange(...) returns a List, which has a 'size' method giving you the number of items in the list.
List l = getObjectsInRange(radius, Actor.class);
int score = l.size();
getWorld().removeObjects(l);
You need to login to post a reply.