0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2024-12-25 13:39:06 -05:00

refactor and tidy

This commit is contained in:
liabru 2022-09-02 17:25:01 +01:00
parent cce3152664
commit 36575b3438
2 changed files with 5 additions and 6 deletions

View file

@ -47,7 +47,7 @@ Example.events = function() {
// apply random forces every 5 secs
if (Common.now() - lastTime >= 5000) {
shakeScene(engine, event.delta);
shakeScene(engine);
// update last time
lastTime = Common.now();
@ -107,15 +107,14 @@ Example.events = function() {
Composite.add(world, stack);
var shakeScene = function(engine, delta) {
var timeScale = delta / 1000;
var shakeScene = function(engine) {
var bodies = Composite.allBodies(engine.world);
for (var i = 0; i < bodies.length; i++) {
var body = bodies[i];
if (!body.isStatic && body.position.y >= 500) {
// Scale force accounting for time delta.
// Scale force accounting for mass
var forceMagnitude = (0.03 * body.mass);
Body.applyForce(body, body.position, {
@ -147,7 +146,7 @@ Example.events = function() {
Events.on(mouseConstraint, 'mousedown', function(event) {
var mousePosition = event.mouse.position;
console.log('mousedown at ' + mousePosition.x + ' ' + mousePosition.y);
shakeScene(engine, event.delta);
shakeScene(engine);
});
// an example of using mouse events on a mouse

View file

@ -400,7 +400,7 @@ var Axes = require('../geometry/Axes');
* Note that this method will ensure that the first part in `body.parts` will always be the `body`.
* @method setParts
* @param {body} body
* @param [body] parts
* @param {body[]} parts
* @param {bool} [autoHull=true]
*/
Body.setParts = function(body, parts, autoHull) {