omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Stoping music in game scene.

    Pythonista
    stop audio audio game scene
    3
    5
    1800
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • resserone13
      resserone13 last edited by

      @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 1 Reply Last reply Reply Quote 0
      • mikael
        mikael @resserone13 last edited by

        @resserone13, sound.stop_all_effects().

        resserone13 1 Reply Last reply Reply Quote 0
        • resserone13
          resserone13 @mikael last edited by

          @mikael was wondering where it would be be placed and how would I have it check if the game is paused or stopped?

          1 Reply Last reply Reply Quote 0
          • JonB
            JonB last edited by

            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.

            resserone13 1 Reply Last reply Reply Quote 0
            • resserone13
              resserone13 @JonB last edited by

              @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.

              1 Reply Last reply Reply Quote 0
              • First post
                Last post
              Powered by NodeBB Forums | Contributors