From f8b64b673ec7159e301601aa6b78bdbaa715f37d Mon Sep 17 00:00:00 2001 From: liabru Date: Sat, 19 Nov 2022 20:52:54 +0000 Subject: [PATCH] change remove example to use timestamps --- examples/remove.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/examples/remove.js b/examples/remove.js index 6fac386..cd4db31 100644 --- a/examples/remove.js +++ b/examples/remove.js @@ -34,7 +34,7 @@ Example.remove = function() { Runner.run(runner, engine); var stack = null, - updateCount = 0; + lastTimestamp = 0; var createStack = function() { return Composites.stack(20, 20, 10, 5, 0, 0, function(x, y) { @@ -62,14 +62,13 @@ Example.remove = function() { }; // add and remove stacks every few updates - Events.on(engine, 'afterUpdate', function() { + Events.on(engine, 'afterUpdate', function(event) { // limit rate - if (stack && updateCount <= 50) { - updateCount += 1; + if (stack && event.timestamp - lastTimestamp < 800) { return; } - updateCount = 0; + lastTimestamp = event.timestamp; // remove last stack if (stack) {