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

2015/11/5

I don't know the correct coding to be able to click in the world and add a new object. Can someone help?

Mack Mack

2015/11/5

#
This is the code I have under the World Class public void act() { if (Greenfoot.mouseClicked(null)) { MouseInfo mouseInfo = Greenfoot.getMouseInfo(); int x = mouseInfo.getX(); int y = mouseInfo.getY(); addObject(new WhatEverClass(), x, y); }
danpost danpost

2015/11/5

#
If you change the conditional to this:
if (Greenfoot.mouseClicked(this))
then, any click in the world that is not also on an actor should cause a WhatEverClass object spawn at the mouse click.
Mack Mack

2015/11/6

#
hello danpost, I changed the conditional like you suggested but when I try to compile I get a syntax error saying "cannot find symbol" referring to WhatEverClass.
Mack Mack

2015/11/6

#
okay never mind I got it. Thank you soooo much danpost you rock!!!!
You need to login to post a reply.