mirror of
https://github.com/liabru/matter-js.git
synced 2024-12-24 13:29:01 -05:00
changed plugins to use body.plugin
This commit is contained in:
parent
b3533937d4
commit
3fdf343015
6 changed files with 18 additions and 10 deletions
|
@ -53,11 +53,13 @@ Example.attractors = function() {
|
|||
radius,
|
||||
{
|
||||
mass: Common.random(10, 15),
|
||||
gravity: G,
|
||||
frictionAir: 0,
|
||||
wrap: {
|
||||
min: { x: 0, y: 0 },
|
||||
max: { x: render.options.width, y: render.options.height }
|
||||
plugin: {
|
||||
gravity: G,
|
||||
wrap: {
|
||||
min: { x: 0, y: 0 },
|
||||
max: { x: render.options.width, y: render.options.height }
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// NOTE: this plugin will be moved to its own repo
|
||||
|
||||
(function() {
|
||||
|
||||
var MatterAttractors = {
|
||||
|
|
|
@ -72,7 +72,7 @@ Example.avalanche = function() {
|
|||
|
||||
// wrapping using matter-wrap plugin
|
||||
for (var i = 0; i < stack.bodies.length; i += 1) {
|
||||
stack.bodies[i].wrap = {
|
||||
stack.bodies[i].plugin.wrap = {
|
||||
min: { x: render.bounds.min.x, y: render.bounds.min.y },
|
||||
max: { x: render.bounds.max.x, y: render.bounds.max.y }
|
||||
};
|
||||
|
|
|
@ -80,7 +80,7 @@ Example.ballPool = function() {
|
|||
var allBodies = Composite.allBodies(world);
|
||||
|
||||
for (var i = 0; i < allBodies.length; i += 1) {
|
||||
allBodies[i].wrap = {
|
||||
allBodies[i].plugin.wrap = {
|
||||
min: { x: render.bounds.min.x - 100, y: render.bounds.min.y },
|
||||
max: { x: render.bounds.max.x + 100, y: render.bounds.max.y }
|
||||
};
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// NOTE: this plugin will be moved to its own repo
|
||||
|
||||
(function() {
|
||||
|
||||
var MatterGravity = {
|
||||
|
@ -19,7 +21,7 @@
|
|||
|
||||
Body: {
|
||||
init: function(body) {
|
||||
if (body.gravity) {
|
||||
if (body.plugin.gravity) {
|
||||
body.attractors.push(MatterGravity.Body.applyGravity);
|
||||
}
|
||||
},
|
||||
|
@ -28,7 +30,7 @@
|
|||
var bToA = Matter.Vector.sub(bodyB.position, bodyA.position),
|
||||
distanceSq = Matter.Vector.magnitudeSquared(bToA) || 0.0001,
|
||||
normal = Matter.Vector.normalise(bToA),
|
||||
magnitude = -bodyA.gravity * (bodyA.mass * bodyB.mass / distanceSq),
|
||||
magnitude = -bodyA.plugin.gravity * (bodyA.mass * bodyB.mass / distanceSq),
|
||||
force = Matter.Vector.mult(normal, magnitude);
|
||||
|
||||
Matter.Body.applyForce(bodyA, bodyA.position, Matter.Vector.neg(force));
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// NOTE: this plugin will be moved to its own repo
|
||||
|
||||
(function() {
|
||||
|
||||
var MatterWrap = {
|
||||
|
@ -21,8 +23,8 @@
|
|||
for (var i = 0; i < bodies.length; i += 1) {
|
||||
var body = bodies[i];
|
||||
|
||||
if (body.wrap) {
|
||||
MatterWrap.Body.wrap(body, body.wrap);
|
||||
if (body.plugin.wrap) {
|
||||
MatterWrap.Body.wrap(body, body.plugin.wrap);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue