Stoping music in game scene.
@JonB I have a game with background music but when I close the game the music still plays. I have to restart Pythonista to stop the play back. How can I fix this?
I currently have the sound in my setup() on the main scene.
class Main(Scene): def setup(self): bg_music = sound.play_effect('3 card monte beat (90.00 BPM) - MAIN OUT.wav', volume=0.25) bg_music.looping = True
@mikael was wondering where it would be be placed and how would I have it check if the game is paused or stopped?
Scenes can define a few optional methods in your scene class. Read the docs for scene.Scene.
Scene.pause() Gets called automatically when the home button is pressed while a scene is running. You can override this to save persistent state for example. The default implementation does nothing. Scene.resume() Gets called automatically when a scene is resumed (after being sent to the background with the home button). The default implementation does nothing. Scene.stop() Gets called automatically when a scene is stopped (by tapping the “x” button). You can override this to save persistent state. The default implementation does nothing.
So, define pause(self) and stop() so that it stops the music, and resume(self) starts it again.
@JonB thanks. I defined everything and added the music code and it’s stopping and starting on cue. Thank you for your help. I wasn’t sure how to use the stop resume and pause. I sometimes still have trouble figuring out little things.