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

2014/2/19

SOUND

GRIFFIN GRIFFIN

2014/2/19

#
I am making a game where there is a song playing in the background, and i am trying to use the constructor function to start the sound. Here is my code: GreenfootSound level1 = new GreenfootSound("level1.mp3"); public MAIN(){ level1.play(); } but when I run the game it plays the song many times one after another. I think the constructor function is calling it more than one time but I don't know why
JetLennit JetLennit

2014/2/19

#
Where is MAIN() called?
GRIFFIN GRIFFIN

2014/2/19

#
MAIN is the actor ( a tank)
JetLennit JetLennit

2014/2/19

#
Try putting the sound in the world's constructor
danpost danpost

2014/2/20

#
Instead of 'level1.play();', use 'if (!level1.isPlaying()) level1.play();' and make the level1 field static. That would be:
static GreenfootSound level1 = new GreenfootSound("level1.mp3");
public MAIN(){
    if (!level1.isPlaying()) level1.play();
}
You need to login to post a reply.