From 6abb3b7e39d055ca42ab9dd0ca677d504381ce47 Mon Sep 17 00:00:00 2001 From: liabru Date: Wed, 7 Apr 2021 22:40:39 +0100 Subject: [PATCH] changed world.gravity to engine.gravity --- examples/compositeManipulation.js | 4 ++-- examples/doublePendulum.js | 4 ++-- examples/gravity.js | 4 ++-- examples/gyro.js | 2 +- src/core/Engine.js | 39 ++++++++++++++++++++++++++++++- 5 files changed, 45 insertions(+), 8 deletions(-) diff --git a/examples/compositeManipulation.js b/examples/compositeManipulation.js index 5633be3..d70b8e2 100644 --- a/examples/compositeManipulation.js +++ b/examples/compositeManipulation.js @@ -47,7 +47,7 @@ Example.compositeManipulation = function() { Composite.add(world, stack); - world.gravity.y = 0; + engine.gravity.y = 0; Events.on(engine, 'afterUpdate', function(event) { var time = engine.timing.timestamp; @@ -107,7 +107,7 @@ Example.compositeManipulation = function() { }; Example.compositeManipulation.title = 'Composite Manipulation'; -Example.compositeManipulation.for = '>=0.14.2'; +Example.compositeManipulation.for = '>0.16.1'; if (typeof module !== 'undefined') { module.exports = Example.compositeManipulation; diff --git a/examples/doublePendulum.js b/examples/doublePendulum.js index a93bc32..056586c 100644 --- a/examples/doublePendulum.js +++ b/examples/doublePendulum.js @@ -52,7 +52,7 @@ Example.doublePendulum = function() { }); }); - world.gravity.scale = 0.002; + engine.gravity.scale = 0.002; Composites.chain(pendulum, 0.45, 0, -0.45, 0, { stiffness: 0.9, @@ -148,7 +148,7 @@ Example.doublePendulum = function() { }; Example.doublePendulum.title = 'Double Pendulum'; -Example.doublePendulum.for = '>=0.14.2'; +Example.doublePendulum.for = '>0.16.1'; if (typeof module !== 'undefined') { module.exports = Example.doublePendulum; diff --git a/examples/gravity.js b/examples/gravity.js index 2608279..274f223 100644 --- a/examples/gravity.js +++ b/examples/gravity.js @@ -41,7 +41,7 @@ Example.gravity = function() { Bodies.rectangle(0, 300, 50, 600, { isStatic: true }) ]); - engine.world.gravity.y = -1; + engine.gravity.y = -1; var stack = Composites.stack(50, 120, 11, 5, 0, 0, function(x, y) { switch (Math.round(Common.random(0, 1))) { @@ -97,7 +97,7 @@ Example.gravity = function() { }; Example.gravity.title = 'Reverse Gravity'; -Example.gravity.for = '>=0.14.2'; +Example.gravity.for = '>0.16.1'; if (typeof module !== 'undefined') { module.exports = Example.gravity; diff --git a/examples/gyro.js b/examples/gyro.js index 47be398..fadac72 100644 --- a/examples/gyro.js +++ b/examples/gyro.js @@ -71,7 +71,7 @@ Example.gyro = function() { if (typeof window !== 'undefined') { var updateGravity = function(event) { var orientation = typeof window.orientation !== 'undefined' ? window.orientation : 0, - gravity = engine.world.gravity; + gravity = engine.gravity; if (orientation === 0) { gravity.x = Common.clamp(event.gamma, -90, 90) / 90; diff --git a/src/core/Engine.js b/src/core/Engine.js index 0539130..1248922 100644 --- a/src/core/Engine.js +++ b/src/core/Engine.js @@ -44,6 +44,11 @@ var Body = require('../body/Body'); events: [], plugin: {}, grid: null, + gravity: { + x: 0, + y: 1, + scale: 0.001 + }, timing: { timestamp: 0, timeScale: 1 @@ -57,6 +62,7 @@ var Body = require('../body/Body'); engine.pairs = Pairs.create(); // temporary back compatibility + engine.world.gravity = engine.gravity; engine.broadphase = engine.grid; engine.metrics = {}; @@ -107,7 +113,7 @@ var Body = require('../body/Body'); Sleeping.update(allBodies, timing.timeScale); // applies gravity to all bodies - Engine._bodiesApplyGravity(allBodies, world.gravity); + Engine._bodiesApplyGravity(allBodies, engine.gravity); // update all body position and rotation by integration Engine._bodiesUpdate(allBodies, delta, timing.timeScale, correction, world.bounds); @@ -451,4 +457,35 @@ var Body = require('../body/Body'); * @type {} */ + /** + * The gravity to apply on all bodies in `engine.world`. + * + * @property gravity + * @type object + */ + + /** + * The gravity x component. + * + * @property gravity.x + * @type object + * @default 0 + */ + + /** + * The gravity y component. + * + * @property gravity.y + * @type object + * @default 1 + */ + + /** + * The gravity scale factor. + * + * @property gravity.scale + * @type object + * @default 0.001 + */ + })();