I have an Actor which when clicked is meant to:
1) Show a preview of the 'shooter' which follows the mouse coordinates
2) When anywhere else on the world is clicked the shooter is to be added
3) The preview is then meant to be removed from the world.
My issue is that when I add in code to remove the preview the preview never shows up in the first place.
Here is the Preview Actor where the preview image is stored:
Then I have the 'BuyShooter' Actor, which is meant to put those steps mentioned above into practice:
public class Preview extends Actor { public Preview(String imageFile) { setImage(imageFile); } /** * Act - do whatever the Preview wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { MouseInfo mouseInfo = Greenfoot.getMouseInfo(); if( mouseInfo == null ) return; setLocation(mouseInfo.getX(), mouseInfo.getY()); } }
public class BuyShooter extends Actor { shooter Shooter = new shooter(); int mouseY, mouseX = 0; MouseInfo mouse = Greenfoot.getMouseInfo(); boolean test = false; Preview preview; public void act() { buy(); } public void buy() { if(Greenfoot.mouseClicked(this)){ preview(); } } if(test == true){ if(Greenfoot.mouseClicked(null)){ if(notOn == false){ MouseInfo mouseInfo = Greenfoot.getMouseInfo(); mouseX = mouseInfo.getX(); mouseY = mouseInfo.getY(); getWorld().addObject(Shooter, mouseX, mouseY); // removePreview(); } public void preview(){ preview = new Preview ("shooter1.png"); getWorld().addObject(preview, mouseX, mouseY); test = true; }