mirror of
https://github.com/liabru/matter-js.git
synced 2024-12-26 13:49:01 -05:00
refactor and tidy
This commit is contained in:
parent
cce3152664
commit
36575b3438
2 changed files with 5 additions and 6 deletions
|
@ -47,7 +47,7 @@ Example.events = function() {
|
||||||
|
|
||||||
// apply random forces every 5 secs
|
// apply random forces every 5 secs
|
||||||
if (Common.now() - lastTime >= 5000) {
|
if (Common.now() - lastTime >= 5000) {
|
||||||
shakeScene(engine, event.delta);
|
shakeScene(engine);
|
||||||
|
|
||||||
// update last time
|
// update last time
|
||||||
lastTime = Common.now();
|
lastTime = Common.now();
|
||||||
|
@ -107,15 +107,14 @@ Example.events = function() {
|
||||||
|
|
||||||
Composite.add(world, stack);
|
Composite.add(world, stack);
|
||||||
|
|
||||||
var shakeScene = function(engine, delta) {
|
var shakeScene = function(engine) {
|
||||||
var timeScale = delta / 1000;
|
|
||||||
var bodies = Composite.allBodies(engine.world);
|
var bodies = Composite.allBodies(engine.world);
|
||||||
|
|
||||||
for (var i = 0; i < bodies.length; i++) {
|
for (var i = 0; i < bodies.length; i++) {
|
||||||
var body = bodies[i];
|
var body = bodies[i];
|
||||||
|
|
||||||
if (!body.isStatic && body.position.y >= 500) {
|
if (!body.isStatic && body.position.y >= 500) {
|
||||||
// Scale force accounting for time delta.
|
// Scale force accounting for mass
|
||||||
var forceMagnitude = (0.03 * body.mass);
|
var forceMagnitude = (0.03 * body.mass);
|
||||||
|
|
||||||
Body.applyForce(body, body.position, {
|
Body.applyForce(body, body.position, {
|
||||||
|
@ -147,7 +146,7 @@ Example.events = function() {
|
||||||
Events.on(mouseConstraint, 'mousedown', function(event) {
|
Events.on(mouseConstraint, 'mousedown', function(event) {
|
||||||
var mousePosition = event.mouse.position;
|
var mousePosition = event.mouse.position;
|
||||||
console.log('mousedown at ' + mousePosition.x + ' ' + mousePosition.y);
|
console.log('mousedown at ' + mousePosition.x + ' ' + mousePosition.y);
|
||||||
shakeScene(engine, event.delta);
|
shakeScene(engine);
|
||||||
});
|
});
|
||||||
|
|
||||||
// an example of using mouse events on a mouse
|
// an example of using mouse events on a mouse
|
||||||
|
|
|
@ -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`.
|
* Note that this method will ensure that the first part in `body.parts` will always be the `body`.
|
||||||
* @method setParts
|
* @method setParts
|
||||||
* @param {body} body
|
* @param {body} body
|
||||||
* @param [body] parts
|
* @param {body[]} parts
|
||||||
* @param {bool} [autoHull=true]
|
* @param {bool} [autoHull=true]
|
||||||
*/
|
*/
|
||||||
Body.setParts = function(body, parts, autoHull) {
|
Body.setParts = function(body, parts, autoHull) {
|
||||||
|
|
Loading…
Reference in a new issue