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

2011/8/13

Looping background music!

m.legere1323 m.legere1323

2011/8/13

#
So I haven't been programming for a few months now...what with life hitting me and whatnot, but now that I'm continuing work on my "Crabgame" I'm trying to figure out how to get background music and how to loop it....how should I go about doing this?
DonaldDuck DonaldDuck

2011/8/14

#
GreenfootSound music = new GreenfootSound("sound.mp3");

if(!music.isPlaying())
{
    music.play();
}
Whenever the sound file is not playing, it will start playing.
ardwennem2 ardwennem2

2011/11/27

#
so... where to put this? Or simply make a new actor?
ardwennem2 ardwennem2

2011/11/27

#
alright... the loop doesn't work for some reason... (tried new actor)
delmar delmar

2011/11/27

#
GreenfootSound also has a playLoop() method.
ardwennem2 ardwennem2

2011/11/28

#
thats... quite usefull
ardwennem2 ardwennem2

2011/11/28

#
if you understand it... could you show me an example where this is used (so a few lines)
DonaldDuck DonaldDuck

2011/11/28

#
Post Deleted.
delmar delmar

2011/11/29

#
The world has two methods, 'started' and 'stopped', that are called when the game is started and stopped. Here is a good place to start and stop your music. Something like this:
private GreenfootSound music = new GreenfootSound("mymusic.mp3");

public void started()
{
    music.playLoop();
}

public void stopped()
{
    music.stop();
}
You need to login to post a reply.