scriptkid Posted August 25, 2016 Share Posted August 25, 2016 I am creating an HTML, JS ,CSS game for android. Can someone write an example for a pause button. PS:I have a timer and it need to be stoped when button is presst. Quote Link to comment Share on other sites More sharing options...
harrywatson Posted August 25, 2016 Share Posted August 25, 2016 paused = true, That should fix all your problems. http://corehtml5canvas.com/code-live/ch05/example-5.9/example.html karhu 1 Quote Link to comment Share on other sites More sharing options...
mattstyles Posted August 26, 2016 Share Posted August 26, 2016 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 () { tick.emit('tick') requestAnimationFrame(ticker) }) function update () { ..stuff } function onGo () { tick.on('tick', update) pauseButton.removeEventListener(onGo) pauseButton.addEventListener(onPause) } function onPause () { tick.off('tick', update) pauseButton.addEventListener(onGo) pauseButton.removeEventListener(onPause) } 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. Kyros2000GameDev and harrywatson 2 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.