mirror of
https://github.com/liabru/matter-js.git
synced 2024-12-24 13:29:01 -05:00
changed world.gravity to engine.gravity
This commit is contained in:
parent
5dbec9bdc6
commit
6abb3b7e39
5 changed files with 45 additions and 8 deletions
|
@ -47,7 +47,7 @@ Example.compositeManipulation = function() {
|
||||||
|
|
||||||
Composite.add(world, stack);
|
Composite.add(world, stack);
|
||||||
|
|
||||||
world.gravity.y = 0;
|
engine.gravity.y = 0;
|
||||||
|
|
||||||
Events.on(engine, 'afterUpdate', function(event) {
|
Events.on(engine, 'afterUpdate', function(event) {
|
||||||
var time = engine.timing.timestamp;
|
var time = engine.timing.timestamp;
|
||||||
|
@ -107,7 +107,7 @@ Example.compositeManipulation = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
Example.compositeManipulation.title = 'Composite Manipulation';
|
Example.compositeManipulation.title = 'Composite Manipulation';
|
||||||
Example.compositeManipulation.for = '>=0.14.2';
|
Example.compositeManipulation.for = '>0.16.1';
|
||||||
|
|
||||||
if (typeof module !== 'undefined') {
|
if (typeof module !== 'undefined') {
|
||||||
module.exports = Example.compositeManipulation;
|
module.exports = Example.compositeManipulation;
|
||||||
|
|
|
@ -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, {
|
Composites.chain(pendulum, 0.45, 0, -0.45, 0, {
|
||||||
stiffness: 0.9,
|
stiffness: 0.9,
|
||||||
|
@ -148,7 +148,7 @@ Example.doublePendulum = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
Example.doublePendulum.title = 'Double Pendulum';
|
Example.doublePendulum.title = 'Double Pendulum';
|
||||||
Example.doublePendulum.for = '>=0.14.2';
|
Example.doublePendulum.for = '>0.16.1';
|
||||||
|
|
||||||
if (typeof module !== 'undefined') {
|
if (typeof module !== 'undefined') {
|
||||||
module.exports = Example.doublePendulum;
|
module.exports = Example.doublePendulum;
|
||||||
|
|
|
@ -41,7 +41,7 @@ Example.gravity = function() {
|
||||||
Bodies.rectangle(0, 300, 50, 600, { isStatic: true })
|
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) {
|
var stack = Composites.stack(50, 120, 11, 5, 0, 0, function(x, y) {
|
||||||
switch (Math.round(Common.random(0, 1))) {
|
switch (Math.round(Common.random(0, 1))) {
|
||||||
|
@ -97,7 +97,7 @@ Example.gravity = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
Example.gravity.title = 'Reverse Gravity';
|
Example.gravity.title = 'Reverse Gravity';
|
||||||
Example.gravity.for = '>=0.14.2';
|
Example.gravity.for = '>0.16.1';
|
||||||
|
|
||||||
if (typeof module !== 'undefined') {
|
if (typeof module !== 'undefined') {
|
||||||
module.exports = Example.gravity;
|
module.exports = Example.gravity;
|
||||||
|
|
|
@ -71,7 +71,7 @@ Example.gyro = function() {
|
||||||
if (typeof window !== 'undefined') {
|
if (typeof window !== 'undefined') {
|
||||||
var updateGravity = function(event) {
|
var updateGravity = function(event) {
|
||||||
var orientation = typeof window.orientation !== 'undefined' ? window.orientation : 0,
|
var orientation = typeof window.orientation !== 'undefined' ? window.orientation : 0,
|
||||||
gravity = engine.world.gravity;
|
gravity = engine.gravity;
|
||||||
|
|
||||||
if (orientation === 0) {
|
if (orientation === 0) {
|
||||||
gravity.x = Common.clamp(event.gamma, -90, 90) / 90;
|
gravity.x = Common.clamp(event.gamma, -90, 90) / 90;
|
||||||
|
|
|
@ -44,6 +44,11 @@ var Body = require('../body/Body');
|
||||||
events: [],
|
events: [],
|
||||||
plugin: {},
|
plugin: {},
|
||||||
grid: null,
|
grid: null,
|
||||||
|
gravity: {
|
||||||
|
x: 0,
|
||||||
|
y: 1,
|
||||||
|
scale: 0.001
|
||||||
|
},
|
||||||
timing: {
|
timing: {
|
||||||
timestamp: 0,
|
timestamp: 0,
|
||||||
timeScale: 1
|
timeScale: 1
|
||||||
|
@ -57,6 +62,7 @@ var Body = require('../body/Body');
|
||||||
engine.pairs = Pairs.create();
|
engine.pairs = Pairs.create();
|
||||||
|
|
||||||
// temporary back compatibility
|
// temporary back compatibility
|
||||||
|
engine.world.gravity = engine.gravity;
|
||||||
engine.broadphase = engine.grid;
|
engine.broadphase = engine.grid;
|
||||||
engine.metrics = {};
|
engine.metrics = {};
|
||||||
|
|
||||||
|
@ -107,7 +113,7 @@ var Body = require('../body/Body');
|
||||||
Sleeping.update(allBodies, timing.timeScale);
|
Sleeping.update(allBodies, timing.timeScale);
|
||||||
|
|
||||||
// applies gravity to all bodies
|
// applies gravity to all bodies
|
||||||
Engine._bodiesApplyGravity(allBodies, world.gravity);
|
Engine._bodiesApplyGravity(allBodies, engine.gravity);
|
||||||
|
|
||||||
// update all body position and rotation by integration
|
// update all body position and rotation by integration
|
||||||
Engine._bodiesUpdate(allBodies, delta, timing.timeScale, correction, world.bounds);
|
Engine._bodiesUpdate(allBodies, delta, timing.timeScale, correction, world.bounds);
|
||||||
|
@ -451,4 +457,35 @@ var Body = require('../body/Body');
|
||||||
* @type {}
|
* @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
|
||||||
|
*/
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
Loading…
Reference in a new issue