mirror of
https://github.com/liabru/matter-js.git
synced 2024-11-23 09:26:51 -05:00
change remove example to use timestamps
This commit is contained in:
parent
903228af47
commit
f8b64b673e
1 changed files with 4 additions and 5 deletions
|
@ -34,7 +34,7 @@ Example.remove = function() {
|
||||||
Runner.run(runner, engine);
|
Runner.run(runner, engine);
|
||||||
|
|
||||||
var stack = null,
|
var stack = null,
|
||||||
updateCount = 0;
|
lastTimestamp = 0;
|
||||||
|
|
||||||
var createStack = function() {
|
var createStack = function() {
|
||||||
return Composites.stack(20, 20, 10, 5, 0, 0, function(x, y) {
|
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
|
// add and remove stacks every few updates
|
||||||
Events.on(engine, 'afterUpdate', function() {
|
Events.on(engine, 'afterUpdate', function(event) {
|
||||||
// limit rate
|
// limit rate
|
||||||
if (stack && updateCount <= 50) {
|
if (stack && event.timestamp - lastTimestamp < 800) {
|
||||||
updateCount += 1;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
updateCount = 0;
|
lastTimestamp = event.timestamp;
|
||||||
|
|
||||||
// remove last stack
|
// remove last stack
|
||||||
if (stack) {
|
if (stack) {
|
||||||
|
|
Loading…
Reference in a new issue