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

2015/5/10

Looping sound?

NewToJavaPlt NewToJavaPlt

2015/5/10

#
I am creating a looping sound in my game but have a issue that it is looping the song over and over the other creating a not so nice sound...?
1
2
3
4
5
6
7
8
9
10
public void musicPlay()
    {
 
        GreenfootSound music = new GreenfootSound("WormMusic.wav");
 
        if(!music.isPlaying())
        {
            music.play();
        }
    }
danpost danpost

2015/5/10

#
The problem is that the GreenfootSound object you just created on line 4 could not be playing (you just created it, so how could it be playing). Each time you call the method, you are creating a new (and different) GreenfootSound object which is not what you want (obviously). move line 4 to before line 1 so you only create one instance of the GreenfootSound class.
NewToJavaPlt NewToJavaPlt

2015/5/11

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