You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Not sure if this is a bug - more likely something I'm not doing and should be. Basically I want to keep rerunning the same simulation over and over with different positions of objects.
The first time it runs, it runs perfectly, very smooth. After that it becomes more and more jumpy, essentially jumping from 'frame 1' of simulation to the end state, without showing any transitional frames.
I had a look at your demo.js to grab the reset code. Is there anything I'm missing here, or is performance when rerunning a simulation a known problem?
function removeBodies(arr) {
for (var i=0;i<arr.length;i++) {
var body = arr[i];
console.log('removing body '+body);
World.remove(engine.world, body);
}
}
function resetSim() {
// reset vars
counter = 0;
timeScale = 1;
finished = false;
runslowdown = false;
numCasualties = 0;
// remove bodies
removeBodies(wallArray);
removeBodies(bodyArray);
removeBodies(particleArray);
World.remove(engine.world, boxA);
// clear arrays
bodyArray.length=0;
casualtyArray.length=0;
particleArray.length=0;
// clear world and engine
World.clear(engine.world);
Engine.clear(engine);
// stop render
Render.stop(render);
// remove events
engine.events = {};
// reset id pool
Body._nextCollidingGroupId = 1;
Body._nextNonCollidingGroupId = -1;
Body._nextCategory = 0x0001;
Common._nextId = 0;
// reset random seed
Common._seed = 0;
setTimeout(startSim, 2000);
}
The text was updated successfully, but these errors were encountered:
Yes removing that Render.stop seems to have made a huge difference, thanks for the tip! :-)
Also, to tag something small on here, the timestamp doesn't seem to return anything when called on a Collision event. e.g.
function collisionStart(event) {
// this works perfectly
console.log(event.pairs.length);
// but this always returns undefined
console.log(event.timestamp)
}
Hey, looks like the docs need to be updated since the timestamp is no longer passed. You should just use engine.timing.timestamp instead when you detect them.
Not sure if this is a bug - more likely something I'm not doing and should be. Basically I want to keep rerunning the same simulation over and over with different positions of objects.
The first time it runs, it runs perfectly, very smooth. After that it becomes more and more jumpy, essentially jumping from 'frame 1' of simulation to the end state, without showing any transitional frames.
I had a look at your demo.js to grab the reset code. Is there anything I'm missing here, or is performance when rerunning a simulation a known problem?
The text was updated successfully, but these errors were encountered: