How to Pause and Resume Music in Your Game

1

Stats

5,909 visits, 8,176 views

Tools

Translations

This tutorial hasn't been translated.

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 12 Feb, 2015. Last updated 19 Feb, 2019

Introduction

So you have made your game and set up everything right?

You also have added a theme music to make it interesting.

Now you probably want to make a pause menu or button so users can feel comfortable pausing and resuming without having to mute their speakers!

Explanation

Note: you must insert the audio object before you start

Note: to find the pause/resume options, just click: add actions > audio > General > set paused

Let me explain to you the events logic before we begin ( you can check the events back and forth so see what I'm talking about ).

1) We start off by a global variable with an initial text value called "onn".

2) We create an event that plays a music file on: layout start & when "onn" is present & when the music file is not already playing.

3) Now when P is clicked, game is paused, thus we need the music to actually pause and not stop right?

So what P does is actually turn the global variable from "onn" to "off".

4) Now we create an event that pauses the "music" file when "off" is present.

5) We need a continue button or event that enables us to turn "off" into "on", you can make whatever condition you want as long as the action is to turn "off" into "on".

In this case i made it easy and set it so that when O is pressed, the global variable is turned into "on"

6) You might be wondering why not "onn", well I learnt this the hard way!

If you let O turn "off" to "onn", you will have double music files playing, 1st one from the on layout start event, and the 2nd from the pause/resume events we're trying to make.

So forget about "onn" and don't let it irritate you!

7) Now that "off" has become "on", we can create an event that resumes the music once it sees the "on" global variable.

Pausing Music Capx

First you need to create a global variable as follows:

Now add these events as follows:

Conclusion

That's it!

I hope that was easy, just remember that there's a difference between "onn" and "on" and you should be fine :)

  • 0 Comments

Want to leave a comment? Login or Register an account!