as stated in the title, I am trying to get it to where a person clicks a button for the tower they want, then click somewhere in the world to place it. I have tried:
in the button, which makes the tower on top of the button, but it doesn't allow me to move it. i have also tried that code with another if statement,
which makes it not work at all. i've tried to put it in the world class, and changed this to an instance of the button, and i can get it to place the tower on the button like before, but i can't get it to move. i've tried separating that code into 2 methods like so:
and that doesn't work either. (ft is an instance of the specific tower)
if(Greenfoot.mouseclicked(this) && m.getMinerals() >= ft.getPrice()) { mineralsSub(ft.getPrice()); MouseInfo mouse = Greenfoot.getMouseInfo(); // addObject(ft, mouse.getX(), mouse.getY()); addObject(new fasttower(), mouse.getX(), mouse.getY()); }
if(Greenfoot.mouseClicked(this) && mins.getMinerals() >= T.getPrice()) { if(Greenfoot.mouseMoved(null)) { if(Greenfoot.mouseClicked(null)) { ((tdpath)getWorld()).mineralsSub(fastPrice); MouseInfo mouse = Greenfoot.getMouseInfo(); (getWorld()).addObject(new fasttower(), mouse.getX(), mouse.getY()); //setLocation(mouse.getX(), mouse.getY()); } } }
public void buttonPressed() { // fasttower ft = new fasttower(); if(Greenfoot.mousePressed(f) && m.getMinerals() >= ft.getPrice()) { mineralsSub(ft.getPrice()); MouseInfo mouse = Greenfoot.getMouseInfo(); // addObject(ft, mouse.getX(), mouse.getY()); addObject(new fasttower(), mouse.getX(), mouse.getY()); } } public void towerPlace() { if(Greenfoot.mousePressed(ft) && Greenfoot.mouseDragged(null)) { if(Greenfoot.mouseDragEnded(null) )//&& !Greenfoot.mousePressed(null))//Greenfoot.mouseClicked(null)) { // ((tdpath)getWorld()).mineralsSub(fastPrice); // mineralsSub(ft.getPrice()); MouseInfo mouse = Greenfoot.getMouseInfo(); ft.setLocation(mouse.getX(), mouse.getY()); // addObject(new fasttower(), mouse.getX(), mouse.getY()); //setLocation(mouse.getX(), mouse.getY()); } } }