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

2017/1/12

Adding music to my game

jacquelinereilly jacquelinereilly

2017/1/12

#
how do I add background music to my game? Thank you
Super_Hippo Super_Hippo

2017/1/12

#
Create a GreenfootSound object, save a reference to it and then you can use methods on it (like looping it, pause, resume, stop). The API can be found here.
jacquelinereilly jacquelinereilly

2017/1/12

#
would you happen to have the code for it
jacquelinereilly jacquelinereilly

2017/1/12

#
i tried it, using the API, and I can't figure it out
Super_Hippo Super_Hippo

2017/1/12

#
//in world subclass
GreenfootSound bgMusic = new GreenfootSound("yourFile.something");

//automatically start/resume when "run" is pressed
public void started()
{
    bgMusic.playLoop();
}

//automatically pause if the scenario is paused
public void stopped()
{
    bgMusic.pause();
}
jacquelinereilly jacquelinereilly

2017/1/13

#
it doesn't work, we did it exactly as you have it with the correct fie name for the song
danpost danpost

2017/1/13

#
jacquelinereilly wrote...
it doesn't work, we did it exactly as you have it with the correct fie name for the song
Please show the code that you tried. Cannot fix unseen code. Need to see where you put everything.
Super_Hippo Super_Hippo

2017/1/13

#
Make sure line 2 is outside any methods. You could also add a 'private' at the start of the line. (It is not needed, but I forgot to add it there.)
jacquelinereilly jacquelinereilly

2017/1/13

#
I got it, thank you
You need to login to post a reply.