This site requires JavaScript, please enable it in your browser!
Greenfoot back
Jaroo
Jaroo wrote ...

2014/3/19

Background Music Help

Jaroo Jaroo

2014/3/19

#
I have added background music into my world using GreenfootSound backgroundMusic = new GreenfootSound("bgmusic.mp3"); but how would I stop that music from playing using one of my actors?
danpost danpost

2014/3/19

#
First, your actor is in the world whose 'backgroundMusic' field contains the sound you are trying to stop; so, you need a reference to the world the actor is in. You can get this by using the Actor class 'getWorld' method. However, this object is only known to the compiler as a World object and the field is not in the World class -- it is in a subclass of the World class. So now, we need to let the compiler know this so that it will look in that class for the field. ((WorldSubclassName)getWorld()).backgroundMusic.stop(); I am sure you did not name your world 'WorldSubclassName''; I think you know what to put there.
Jaroo Jaroo

2014/3/19

#
Thanks for the reply! I was able to get it working without any problems.
You need to login to post a reply.