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

2016/3/5

Problems with changing a sound

Vellyxenya Vellyxenya

2016/3/5

#
Hi, I'm trying to making the sound played depend on the current Level (a sound for each level) I tried this code:
public static GreenfootSound gameMusic = new GreenfootSound("test.AIF");
public void act()
    {
        ChangeMouseImage(img1, 1, 1);
        switch(Level)
        {
            case 1: gameMusic.playLoop(); break;
            case 2:
            gameMusic.stop();
            if(bossCounter == 10)
            {
                gameMusic = new GreenfootSound("trytry.wav");
                gameMusic.playLoop();
            }
            break;
        }
}
But the music doesn't change... any idea how to fix that please? (The BossCounter is reinitialized after each level)
Super_Hippo Super_Hippo

2016/3/5

#
Where do you increase the 'bossCounter'? Btw, why is 'gameMusic' static?
Vellyxenya Vellyxenya

2016/3/5

#
It's only a little part of the act method, the increase of bossCounter is some lines after this thread. I checked and I don't think the problem is caused by the counter. In fact, the gameMusic is static because I need it in another class where I can change the volume.
Vellyxenya Vellyxenya

2016/3/5

#
and the purpose of having only one variable for all the tracks is because in the other class where I change the volume, there are codes like: 'if(//.....)gameMusic.setVolume(50); etc...
Super_Hippo Super_Hippo

2016/3/5

#
Does the music stop at all? In other words, where do you change 'Level'?
Vellyxenya Vellyxenya

2016/3/5

#
Yes the music stops, and the level increases, but the new sound doesn't start
Super_Hippo Super_Hippo

2016/3/5

#
Maybe the 'bossCounter' is already higher than 10 when 'Level' is 2?
Vellyxenya Vellyxenya

2016/3/5

#
Okay, so I tried this:
switch(Level)
        {
            case 1: gameMusic.playLoop(); break;
            case 2:
            if(bossCounter == 10) gameMusic.stop();
            else if(bossCounter == 11) 
            {
                gameMusic = new GreenfootSound("trytry.wav");
                gameMusic.playLoop();
            }
            break;
        }
and it works! Indeed, the problem was with the counter: apparently if there's a 'gameMusic.stop()' and a 'gameMusic.playLoop()' in the same act, it doesn't do anything^^ Thank you very much for your help! :D
Super_Hippo Super_Hippo

2016/3/5

#
Ok... well, I didn't know that ;)
You need to login to post a reply.