Hi all, I've just started coding a few days ago so I apologize if I don't understand any terminology.
So right now i'm making this game that has background music in the PlayWorld world through the Music actor that I have placed in that world specifically so I have background music just in that world (Because I have other worlds in which I don't want background music in). However I have decided that I wanted some game settings in a Settings world such as an option to mute the background music in the PlayWorld world.
I had an idea where I could have a button where if it is pressed it removes the the Music actor from the PlayWorld world, hence "muting" the background music. But correct me if I'm wrong, for that to happen I need to reference the worlds which I'm not sure how to do.
If there is a better way to have background music in the PlayWorld world and have an option to mute it in the Settings world please let me know.
This is what I'm ultimately trying to aciehve if there is no better way to mute bg music in PlayWorld world.
}
This is my code for background music in the PlayWorld world
Thanks in advance
1 2 3 4 5 6 7 8 9 10 11 12 | public class MuteButton extends Actor { public void act() { click(); } public void click() { if (Greenfoot.mouseClicked( this )) { getWorld().removeObject (Music); |
1 2 3 4 5 6 7 8 9 10 11 12 | public class Music extends Actor { GreenfootSound music = new GreenfootSound( "bgM.wav" ); /** * Act - do whatever the Music wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { music.playLoop(); } } |