Skip to content

Commit 6abb3b7

Browse files
committed
changed world.gravity to engine.gravity
1 parent 5dbec9b commit 6abb3b7

5 files changed

Lines changed: 45 additions & 8 deletions

File tree

examples/compositeManipulation.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Example.compositeManipulation = function() {
4747

4848
Composite.add(world, stack);
4949

50-
world.gravity.y = 0;
50+
engine.gravity.y = 0;
5151

5252
Events.on(engine, 'afterUpdate', function(event) {
5353
var time = engine.timing.timestamp;
@@ -107,7 +107,7 @@ Example.compositeManipulation = function() {
107107
};
108108

109109
Example.compositeManipulation.title = 'Composite Manipulation';
110-
Example.compositeManipulation.for = '>=0.14.2';
110+
Example.compositeManipulation.for = '>0.16.1';
111111

112112
if (typeof module !== 'undefined') {
113113
module.exports = Example.compositeManipulation;

examples/doublePendulum.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Example.doublePendulum = function() {
5252
});
5353
});
5454

55-
world.gravity.scale = 0.002;
55+
engine.gravity.scale = 0.002;
5656

5757
Composites.chain(pendulum, 0.45, 0, -0.45, 0, {
5858
stiffness: 0.9,
@@ -148,7 +148,7 @@ Example.doublePendulum = function() {
148148
};
149149

150150
Example.doublePendulum.title = 'Double Pendulum';
151-
Example.doublePendulum.for = '>=0.14.2';
151+
Example.doublePendulum.for = '>0.16.1';
152152

153153
if (typeof module !== 'undefined') {
154154
module.exports = Example.doublePendulum;

examples/gravity.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Example.gravity = function() {
4141
Bodies.rectangle(0, 300, 50, 600, { isStatic: true })
4242
]);
4343

44-
engine.world.gravity.y = -1;
44+
engine.gravity.y = -1;
4545

4646
var stack = Composites.stack(50, 120, 11, 5, 0, 0, function(x, y) {
4747
switch (Math.round(Common.random(0, 1))) {
@@ -97,7 +97,7 @@ Example.gravity = function() {
9797
};
9898

9999
Example.gravity.title = 'Reverse Gravity';
100-
Example.gravity.for = '>=0.14.2';
100+
Example.gravity.for = '>0.16.1';
101101

102102
if (typeof module !== 'undefined') {
103103
module.exports = Example.gravity;

examples/gyro.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ Example.gyro = function() {
7171
if (typeof window !== 'undefined') {
7272
var updateGravity = function(event) {
7373
var orientation = typeof window.orientation !== 'undefined' ? window.orientation : 0,
74-
gravity = engine.world.gravity;
74+
gravity = engine.gravity;
7575

7676
if (orientation === 0) {
7777
gravity.x = Common.clamp(event.gamma, -90, 90) / 90;

src/core/Engine.js

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ var Body = require('../body/Body');
4444
events: [],
4545
plugin: {},
4646
grid: null,
47+
gravity: {
48+
x: 0,
49+
y: 1,
50+
scale: 0.001
51+
},
4752
timing: {
4853
timestamp: 0,
4954
timeScale: 1
@@ -57,6 +62,7 @@ var Body = require('../body/Body');
5762
engine.pairs = Pairs.create();
5863

5964
// temporary back compatibility
65+
engine.world.gravity = engine.gravity;
6066
engine.broadphase = engine.grid;
6167
engine.metrics = {};
6268

@@ -107,7 +113,7 @@ var Body = require('../body/Body');
107113
Sleeping.update(allBodies, timing.timeScale);
108114

109115
// applies gravity to all bodies
110-
Engine._bodiesApplyGravity(allBodies, world.gravity);
116+
Engine._bodiesApplyGravity(allBodies, engine.gravity);
111117

112118
// update all body position and rotation by integration
113119
Engine._bodiesUpdate(allBodies, delta, timing.timeScale, correction, world.bounds);
@@ -451,4 +457,35 @@ var Body = require('../body/Body');
451457
* @type {}
452458
*/
453459

460+
/**
461+
* The gravity to apply on all bodies in `engine.world`.
462+
*
463+
* @property gravity
464+
* @type object
465+
*/
466+
467+
/**
468+
* The gravity x component.
469+
*
470+
* @property gravity.x
471+
* @type object
472+
* @default 0
473+
*/
474+
475+
/**
476+
* The gravity y component.
477+
*
478+
* @property gravity.y
479+
* @type object
480+
* @default 1
481+
*/
482+
483+
/**
484+
* The gravity scale factor.
485+
*
486+
* @property gravity.scale
487+
* @type object
488+
* @default 0.001
489+
*/
490+
454491
})();

0 commit comments

Comments
 (0)