mirror of
https://github.com/liabru/matter-js.git
synced 2024-11-27 09:50:52 -05:00
change gravity scale to variable rather than a constant
This commit is contained in:
parent
5ff218234a
commit
a38b22721c
2 changed files with 51 additions and 8 deletions
|
@ -34,7 +34,11 @@ var Common = require('../core/Common');
|
|||
|
||||
var defaults = {
|
||||
label: 'World',
|
||||
gravity: { x: 0, y: 1 },
|
||||
gravity: {
|
||||
x: 0,
|
||||
y: 1,
|
||||
scale: 0.001
|
||||
},
|
||||
bounds: {
|
||||
min: { x: -Infinity, y: -Infinity },
|
||||
max: { x: Infinity, y: Infinity }
|
||||
|
@ -44,18 +48,55 @@ var Common = require('../core/Common');
|
|||
return Common.extend(composite, defaults, options);
|
||||
};
|
||||
|
||||
/*
|
||||
*
|
||||
* Properties Documentation
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* The gravity to apply on the 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
|
||||
*/
|
||||
|
||||
// World is a Composite body
|
||||
// see src/module/Outro.js for these aliases:
|
||||
|
||||
/**
|
||||
* An alias for Composite.clear since World is also a Composite
|
||||
* An alias for Composite.clear
|
||||
* @method clear
|
||||
* @param {world} world
|
||||
* @param {boolean} keepStatic
|
||||
*/
|
||||
|
||||
/**
|
||||
* An alias for Composite.add since World is also a Composite
|
||||
* An alias for Composite.add
|
||||
* @method addComposite
|
||||
* @param {world} world
|
||||
* @param {composite} composite
|
||||
|
@ -63,7 +104,7 @@ var Common = require('../core/Common');
|
|||
*/
|
||||
|
||||
/**
|
||||
* An alias for Composite.addBody since World is also a Composite
|
||||
* An alias for Composite.addBody
|
||||
* @method addBody
|
||||
* @param {world} world
|
||||
* @param {body} body
|
||||
|
@ -71,7 +112,7 @@ var Common = require('../core/Common');
|
|||
*/
|
||||
|
||||
/**
|
||||
* An alias for Composite.addConstraint since World is also a Composite
|
||||
* An alias for Composite.addConstraint
|
||||
* @method addConstraint
|
||||
* @param {world} world
|
||||
* @param {constraint} constraint
|
||||
|
|
|
@ -280,7 +280,9 @@ var Body = require('../body/Body');
|
|||
* @param {vector} gravity
|
||||
*/
|
||||
var _bodiesApplyGravity = function(bodies, gravity) {
|
||||
if (gravity.x === 0 && gravity.y === 0) {
|
||||
var gravityScale = typeof gravity.scale !== 'undefined' ? gravity.scale : 0.001;
|
||||
|
||||
if ((gravity.x === 0 && gravity.y === 0) || gravityScale === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -291,8 +293,8 @@ var Body = require('../body/Body');
|
|||
continue;
|
||||
|
||||
// apply gravity
|
||||
body.force.y += body.mass * gravity.y * 0.001;
|
||||
body.force.x += body.mass * gravity.x * 0.001;
|
||||
body.force.y += body.mass * gravity.y * gravityScale;
|
||||
body.force.x += body.mass * gravity.x * gravityScale;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue