Jump to content

Pause Button


Recommended Posts

Depends how you've coded your timer, show us that code for a better answer.

Another way that is a better general approach (this approach scales better and is more flexible) is to simply apply/remove (subscribe/unsubcribe) functions to a slave tick emitter in response to events that control whether your game is paused or running, and it just so happens you have a very handy slave right there in the browser with no work, requestAnimationFrame.

var tick = new EventEmitter()

requestAnimationFrame(function ticker () {

function update () {

function onGo () {
  tick.on('tick', update)

function onPause () {
  tick.off('tick', update)

 This way you could set up multiple timers, or limit some timers, or set up an observable slaved to the tick emitter for more control, etc etc etc.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...