Tutorial: Integrate Game Breaks
Prerequisite: make sure you integrate the Game API and it’s loading correctly before continuing (see Load the API).
Game breaks are moments in the game when you have a natural pause in the game flow such as a level change.
They are offering us the ability to pause the game and display a message to the users, we mostly use them to display in-game ads. Therefore in order to have in-game ads to your game, you need to implement Game Breaks; the rest is up to us. We make sure that users aren’t exposed to too much advertising and get the most relevant ads.
You should request a Game Break during a logical pause of the game, for example level change, and you should be able to pause the music and the animation of your game.
Three simple rules
- Game Breaks requests (Natural moments) can be called as often as you want. We will allow them once a time.
- Game Break requests are accepted asynchronously, make sure that your game will continue to play only after the resumeGame callback is triggered.
- Your game must also mute the sound when it’s paused.
Pausing and Resuming your game
Implement two (global) functions in your game so it can be paused and resumed. While the pause method will be called only when there is an ad to be displayed the resume will always be triggered in the end of the process. For this example we will create two placeholders showing a console log:
Calling a Game Break request
After setting up your pause and resume functions, calling a Game Break request is simple. Just implement the following line on all possible natural break moments: