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?


1 2 3 4 5 6 | //in the object you want to click to change the world; public void act() { if (Greenfoot.mouseClicked( this )) { Greenfoot.setWorld( new NextWorld()); } } |
1 2 3 4 5 | 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 ; } |
1 2 3 4 5 6 7 8 9 | //in the class that should be transparent; public void act() { if (mouseOnObject( this )) { setTransparenzy( 0 ); } else { setTransparenzy( 255 ); } } |
1 2 | if (Greenfoot.mouseMoved( this )) setTransparency( 0 ); if (Greenfoot.mouseMoved( null ) && !Greenfoot.mouseMoved( this )) setTransparency( 255 ); |
1 2 | if (Greenfoot.mouseMoved( this )) getImage().setTransparency( 0 ); if (Greenfoot.mouseMoved( null ) && !Greenfoot.mouseMoved( this )) getImage().setTransparency( 255 ); |