diff --git a/docs/sheets/2-animation.md b/docs/sheets/2-animation.md index fbf2a5a..a6f9a66 100644 --- a/docs/sheets/2-animation.md +++ b/docs/sheets/2-animation.md @@ -323,18 +323,7 @@ Finally, if we don't destroy the bullets, eventually the game will get really sl ``` _This should go inside the bullet's `forever`, just after the code to move it._ -The `destroy()` function attached to a Sprite removes it from the screen permanently. - -However, we haven't quite cleaned up after ourselves--the forever block for the bullet will keep running, even though it's no longer on screen! This isn't super-important, but in larger games it might cause us to run out of memory. So let's `return false` to stop the `forever` block from running: - - * We should also `return false`, to make sure the `forever` block stops. - - ```js - if (!bullet.isOnScreen()) { - bullet.destroy() - return false // stop this forever block - } - ``` +The `destroy()` function attached to a Sprite removes it from the screen permanently. This also stops any `forever` loops attached to it. ## Fin diff --git a/uw/index.js b/uw/index.js index c1c0851..1593286 100644 --- a/uw/index.js +++ b/uw/index.js @@ -153,7 +153,6 @@ var World = function(props) { document.body.style.margin = '0px' document.body.appendChild(this._wrap) this._resize() - this._deadLoops = [] window.addEventListener('resize', () => { this._needsResize = true }) this._bindPointer() @@ -174,7 +173,7 @@ var World = function(props) { this.stop = this.stop.bind(this) this.start() } -emitter(World.prototype, ['frame', 'tap', 'drag', 'drop']) +emitter(World.prototype, ['tick', 'tap', 'drag', 'drop']) World.prototype.start = function() { if (this.isRunning) return @@ -194,7 +193,9 @@ World.prototype.pause = function() { World.prototype.stop = function() { if (!this.isRunning) return this.pause() - this._deadLoops = this._deadLoops.concat(this.listeners('frame')) + for (var i=0; i