all it's missing is var isRunning = true; in the global scope, if(!isRunning) { return; } window.on('stopRunning', function() { isRunning = false; }); in bar() and processEvents(); in foo()
Generally, with something like a game loop, there's going to be some sort of state being stored at the global scope. For instance, I might store the player there. But most things should rely solely on events, and anything in the global scope should be kept to a minimum.
Eh? It doesn't have to be global. Assuming that only the loop needs to be aware that it's running, you can encapsulate it in something where it isn't accessible.
33
u/fukitol- Apr 12 '16
all it's missing is
var isRunning = true;in the global scope,if(!isRunning) { return; } window.on('stopRunning', function() { isRunning = false; });inbar()andprocessEvents();infoo()It's practically a game!