I'm having some difficulties with using the getObjectsInRange-method from the Actor.class.
I read the description in the GreenfootDocumentation and it says the radius is measured in cells.
No matter what I type in for the radius and no matter how far my Hero is away from the Box ( which checks on the Range of the Hero) the the method always return that the Hero is in Range.
Here's my code:
I guess my problem is that I don't quite understand how a world is build. A world is build with the following
super(int worldWidth, int worldHeight, int cellSize).
My level1 world is has the following size: super(1100,550,1). That would mean a world with 1100x550 cells with a cell size of 1x1 pixels.
This would mean, that the box shouldn't even turn red, because the center of Hero and the center of Box can't even come as close, as they need to trigger the if-clause true, because there is some code in Hero that prevents collision of those two.
Did I misunderstand something? What am I doing wrong? I already tried making the world with bigger cells, but still the same results. Is there a preference in greenfoot that can make the cells visible via a grid?
Thank you
public class Box extends Obstacle { public void turnRed() { getImage().setColor(new Color(255,0,0)); getImage().fill(); } public void turnBlue() { getImage().setColor(new Color(0,0,255)); getImage().fill(); } public void act() { if(getObjectsInRange(1,Hero.class) != null) turnRed(); else turnBlue(); }