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

2020/3/31

need help using MouseClicked method with an actor

Joshua09 Joshua09

2020/3/31

#
private void checkMouseClick() { \\if (Greenfoot.mouseClicked(null)) if (Greenfoot.mouseClicked(Block.class)) //if (Greenfoot.mouseClicked(World.class)) { World world = getWorld(); List<Leaf> leaves = world.getObjects(Leaf.class); for (Leaf leaf : leaves) { leaf.changeImage(); } } } I'm trying to have it to where when i click the block it will change all the leaves color. I'm not sure if I'm passing the parameter of Block.class wrong or what.. Also how would I pass the MyWorld.Class as the parameter in the if statement. I've tried using it and it wont recognize any clicks.
danpost danpost

2020/3/31

#
The mouseClicked method does not look for clicks on classes. It looks for clicks on a specific object (or any click when the argument is null). If the code given is in your Block class you can use this as the argument. For the world, you can simply use getWorld() for the argument.
You need to login to post a reply.