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

2016/1/12

Left-Half

RickAstley44 RickAstley44

2016/1/12

#
private void checkMouseClick() { if (Greenfoot.mouseClicked(null)) { World world = getWorld(); List<Leaf> leaves = world.getObjects(Leaf.class); for (Leaf leaf : leaves) { leaf.changeImage(); } } } How do I edit this code so that only leaves on the left half of the 600 by 400 world change image?
danpost danpost

2016/1/12

#
Place the condition on the line that changes the images of the leaves. The left half of the world has x-coordinate values between zero and half the width of the world; so, the condition would be that the x-coordinate of the location of the leaf is less than half the width of the world (regardless the size of the world).
You need to login to post a reply.