Skip to content

Commit

Permalink
changed world.gravity to engine.gravity
Browse files Browse the repository at this point in the history
  • Loading branch information
liabru committed Apr 7, 2021
1 parent 5dbec9b commit 6abb3b7
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 8 deletions.
4 changes: 2 additions & 2 deletions examples/compositeManipulation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions examples/doublePendulum.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions examples/gravity.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))) {
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion examples/gyro.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
39 changes: 38 additions & 1 deletion src/core/Engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = {};

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
*/

})();

0 comments on commit 6abb3b7

Please sign in to comment.