If I wanted to click on an object to change worlds, where would I have to put the code? Would it be in the world class or actor class?


//in the object you want to click to change the world; public void act() { if (Greenfoot.mouseClicked(this)) { Greenfoot.setWorld(new NextWorld()); } }
private boolean mouseOnObject(Actor actor) { MouseInfo mouse = Greenfoot.getMouseInfo(); return mouse != null && mouse.getX() > actor.getX() - actor.getImage().getWidth()/2 && mouse.getX() < actor.getX() + actor.getImage().getWidth()/2 && mouse.getY() > actor.getY() - actor.getImage().getHeight()/2 && mouse.getY() < actor.getY() + actor.getImage().getHeight()/2; }
//in the class that should be transparent; public void act() { if (mouseOnObject(this)) { setTransparenzy(0); } else { setTransparenzy(255); } }
if (Greenfoot.mouseMoved(this)) setTransparency(0); if (Greenfoot.mouseMoved(null) && !Greenfoot.mouseMoved(this)) setTransparency(255);
if (Greenfoot.mouseMoved(this)) getImage().setTransparency(0); if (Greenfoot.mouseMoved(null) && !Greenfoot.mouseMoved(this)) getImage().setTransparency(255);