I am a newbie at programming/Greenfoot, and wanted to create a simple strategy game, where you get to choose where you place your base first. I wanted to create a code which detects where the mouse is and if the mouse is clicked, the base and the character will be placed on that location. I came up with the idea to create a seperate invisible actor which sits at the corner of the map. The seethrough model/texture is so tiny that it is very unlikely that one would accidentaly clicked on it. The code that the actor has is as following:
When I click the mouse, nothing happens, can someone tell me what is wrong and how to fix it? (Sorry for my english I am not a native speaker)
int limit;
int mx;
int my;
public void act()
{
MouseInfo mouse =
Greenfoot.getMouseInfo();
if(mouse!=null){
mx = mouse.getX();
my = mouse.getY();
}
if(Greenfoot.mouseClicked(MyWorld.class))
{
if(limit<1) {
getWorld().addObject(new Player(), mx, my);
getWorld().addObject(new Base(), mx, my);
limit++;
}
}
}