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

2013/4/8

How to find actors in radius?

GreenGoo GreenGoo

2013/4/8

#
I would like to use the method getObjectsInRange() but I don't know how to use it. I need it to return a boolean. How do I do this?
davmac davmac

2013/4/8

#
I need it to return a boolean
You can't make a method return a different type to what it does return. I think what you probably mean is, you want to check whether there exist any actors in a certain radius. In that case, just call getObjectsInRange() and call isEmpty() on the result to check whether there are no actors in range.
boolean result = ! getObjectsInRange(100, Actor.class).isEmpty();
... will set result to true if there are any actors within a 100 cell radius.
You need to login to post a reply.