0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2024-11-27 09:50:52 -05:00

change remove example to use timestamps

This commit is contained in:
liabru 2022-11-19 20:52:54 +00:00
parent 903228af47
commit f8b64b673e

View file

@ -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) {