tyoo Posted February 28, 2015 Share Posted February 28, 2015 Hi, I´m programing a javascript game, but i´cant find out how to do a pause/play on it. I alredy find a way to stop all interval´s and timeout´s but i can´t start them all, just if i do it one by one. To stop them all e do the next: var highestTimeoutId = setTimeout(";");for (var i = 0; i < highestTimeoutId; i++) {clearTimeout(i); Exist some way to do it with jquery or something else? Thanks Quote Link to comment Share on other sites More sharing options...
AzraelTycka Posted March 1, 2015 Share Posted March 1, 2015 Hello,I'm having troubles understanding what exactly you are looking for here. If you set timeouts up and than clear them then you obviously need to start new ones in the same way as you did at the beginning - as you said one by one, logic dictates there is no other way around it.Depending on your game you can integrate pause function into your game in a simplier way, the simplest one would be to just set some variable to some value and wrapping everything in your loops in if condition, such as this (though not perfect):var obj = {pause: false};for () { // here starts the game loop if (!obj.pause) { // here comes all the game code, when the game is paused obj.pause = true, thus all the game code is ignored, thus the game isn't progressing until you change obj.pause back to false }} // here ends the game loop// if you use this way you don't need to stop intervalsWell this is just one simple way how to integrate puse into your game, depending on how complex your game is you might want to do it in some other way.Here is I guess a similar question about pausing a timeout in javascript.(btw are you sure you need timeouts in your game, perhaps changing the logic to requestAnimationFrame would make your life easier as it is nowadays preferable way to do game loops in browsers - just curious?) 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.