Skip to content

Pause, breaks and audio

A grown-up can pause the game from the phone (or a child, with the X reserved to Fabi Play; and Fabi Play pauses it by itself when nobody has been in the picture for 3 seconds: see Reserved to Fabi Play). The game gets pause, then resume: stop the clock in between.

FabiPlay.on('pause', () => game.pause())
FabiPlay.on('resume', () => game.resume())

Fabi Play draws the pause menu itself; the game draws nothing for it.

Why it paused. pause says why, in reason: 'user', a grown-up (the phone, the remote) or a child’s crossed arms. Hosts before this send no reason; take it as 'user'.

The protocol also has 'distance', for a child standing too close to the screen. Fabi Play no longer pauses for distance, so games never get reason: 'distance' from it. A game that already handles it needs no change: stop the clock until resume, whatever the reason.

FabiPlay.on('pause', ({ reason }) => game.pause()) // reason: 'user'

Fabi Play draws its own small pause button over your game, in the top-right corner: a 64 × 64 px square inside the safe area (init.safeArea), in CSS pixels of the page. On a tablet or a phone playing alone it is touched; on a TV whose children are seen by a camera, the LG Magic Remote’s pointer can click it, and in games whose movements don’t include hands a child pauses by stretching an arm up and to the right and keeping the hand still on it for 2 seconds (a ring fills around it). In hands games the hand never presses it. Keep your top-right HUD (score, level, round, words) clear of it, or move it left by that much there. On a TV the button is bigger and kept away from the edges a TV may cut off: keep the top-right 88 × 88 px clear there (of a 1280 × 720 page; scale it with the page’s width). A hand in that corner still reaches your game as usual. While the TV remote plays there is no button (the remote’s legend and the phone’s reminder use the bottom corners: see The TV remote).

Fabi Play decides on and shows the ads, never the game. The game only says when it has stopped on its own:

await FabiPlay.break('level') // a level is over: the best moment
await FabiPlay.break('gameover') // match over, another is about to start

With no reason, break() means 'level'. The game’s pause menu is never a moment for an ad: a child who stops for a moment must not get an ad. A break with any other reason (for example 'pause') gets break-done immediately, with no ad.

What happens next:

  • If the rules allow it, break-start arrives: Fabi Play shows the ad over the game.
  • Without an ad, break-done may come up to a couple of seconds late, with no break-start before it: the screen is framing the children again (automatic framing) and the view changes meanwhile. Keep drawing the avatars where view says; your sound goes on.
  • break-done always follows, and break() resolves: the game resumes. The value is true if an ad was shown.
  • The game always gets the answer, so it never stays stuck.
  • Do not call break() while the child is playing.
FabiPlay.on('break-start', () => game.freeze()) // stop timers and animations
FabiPlay.on('break-end', ({ shown }) => game.unfreeze())

With npm, the events are break-start and break-done ({ shown }), and play.break(reason) resolves the same way.

The same for every game played that evening:

  • no ads in the first 5 minutes;
  • at least 8 minutes between two ads;
  • these minutes are play time: pauses, ads and the time between games don’t count;
  • at most 3 per session;
  • ads only from Fabi Play’s ad server: contextual, not personalised, checked by a person;
  • between one game and the next Fabi Play may show an ad without asking the game anything. Even a game that never calls break() earns revenue.

In the simulator, «Pubblicità a ogni pausa» (Ad at every break) gives every break() a fake 3-second ad, without waiting for the 5 minutes the rules require (see Testing with the simulator).

With the script tag you do not need to do anything about audio. During an ad fabi-play.js pauses every <audio> and <video> in the page and suspends Web Audio contexts, then starts them again. It can only see the Web Audio contexts created after it, so load it before the game’s scripts. To handle audio yourself, put data-mute="manual" on the script tag.

With npm the same is one call, muteDuringBreaks(play), made before the game creates its audio contexts:

import { connect, muteDuringBreaks } from '@fabiplay/sdk'
const connecting = connect()
muteDuringBreaks(connecting) // takes the Play or the promise of it
const play = await connecting

Muted screens. play.muted (npm) says the screen’s sound is off when the game starts: start the game muted.

The engine does all of this for its own sounds: they stop with pauses and breaks and stay quiet while the screen is muted.