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

2019/3/19

Stoping sound when a world changes

Erasedsword Erasedsword

2019/3/19

#
I’m having another issue regarding sound. Instead of an error because I mis-clicked. I’m now having issues with the play loop method. I’m trying to stop it when it changes worlds, however using this, it either doesn’t play, or just to the next world without stoping. If possible can you make the code as simple as possible I’ve also looked at the old posts regarding this, however I can not understand how they work This makes it very difficult to use the code for my game. Lastly I’m using an outdated version of Greenfoot. It is version 2.4.2
danpost danpost

2019/3/19

#
Erasedsword wrote...
I’m having another issue regarding sound. Instead of an error because I mis-clicked. I’m now having issues with the play loop method. I’m trying to stop it when it changes worlds, however using this, it either doesn’t play, or just to the next world without stoping. If possible can you make the code as simple as possible I’ve also looked at the old posts regarding this, however I can not understand how they work This makes it very difficult to use the code for my game. Lastly I’m using an outdated version of Greenfoot. It is version 2.4.2
Add the following to your Space class:
public void stopped()
{
    music.stop();
}
Then, add the following like where you create the new world (presuming from an Actor subclass):
((Space)getWorld()).stopped();
Erasedsword Erasedsword

2019/3/19

#
I don’t think that would work for me since 1. The change is in the current world, and 2. It changes with a set key. So when the key is released the sound starts to play again
Erasedsword Erasedsword

2019/3/19

#
I just figured out that I had the methods called in the wrong order. It’s working fine niw
You need to login to post a reply.