How do I pass a variable between different worlds?


1 2 3 4 | if (Greenfoot.mouseClicked( this )) { Greenfoot.setWorld( new MyWorld()); } |
1 2 | MyWorld mw = new MyWorld(); Greenfoot.setWorld(mw); |
1 | boolean wantsToPlay = ((MusicToggle)getWorld(),getObjects(MusicToggle. class ).get( 0 )).wantsMusic; |
1 | mw.wantsMusic = wantsToPlay; |
1 2 3 4 5 6 | if (Greenfoot.mouseClicked( this )) { MyWorld mw = new MyWorld(); mw.wantsMusic = ((MusicToggle)getWorld().getObjects(MusicToggle. class ).get( 0 )).wantsMusic; Greenfoot.setWorld(mw); } |
1 | mw.started(); |
1 | if (alpha > 0 ) getImage().setTransparency(( int )alpha); else getWorld().removeObject( this ); |
1 | if (alpha == 0 ) getWorld().removeObject( this ); else getImage().setTransparency(( int )alpha); |