0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2025-01-21 17:14:38 -05:00

change all examples to use Composite.add instead of the alias World.add

This commit is contained in:
liabru 2021-04-06 21:36:43 +01:00
parent 9ad980b975
commit a3f298fedb
43 changed files with 159 additions and 169 deletions

View file

@ -6,7 +6,7 @@ Example.airFriction = function() {
Runner = Matter.Runner, Runner = Matter.Runner,
MouseConstraint = Matter.MouseConstraint, MouseConstraint = Matter.MouseConstraint,
Mouse = Matter.Mouse, Mouse = Matter.Mouse,
World = Matter.World, Composite = Matter.Composite,
Bodies = Matter.Bodies; Bodies = Matter.Bodies;
// create engine // create engine
@ -31,7 +31,7 @@ Example.airFriction = function() {
Runner.run(runner, engine); Runner.run(runner, engine);
// add bodies // add bodies
World.add(world, [ Composite.add(world, [
// falling blocks // falling blocks
Bodies.rectangle(200, 100, 60, 60, { frictionAir: 0.001 }), Bodies.rectangle(200, 100, 60, 60, { frictionAir: 0.001 }),
Bodies.rectangle(400, 100, 60, 60, { frictionAir: 0.05 }), Bodies.rectangle(400, 100, 60, 60, { frictionAir: 0.05 }),
@ -56,7 +56,7 @@ Example.airFriction = function() {
} }
}); });
World.add(world, mouseConstraint); Composite.add(world, mouseConstraint);
// keep the mouse in sync with rendering // keep the mouse in sync with rendering
render.mouse = mouse; render.mouse = mouse;

View file

@ -21,7 +21,6 @@ Example.avalanche = function() {
Common = Matter.Common, Common = Matter.Common,
MouseConstraint = Matter.MouseConstraint, MouseConstraint = Matter.MouseConstraint,
Mouse = Matter.Mouse, Mouse = Matter.Mouse,
World = Matter.World,
Bodies = Matter.Bodies; Bodies = Matter.Bodies;
// create engine // create engine
@ -50,9 +49,9 @@ Example.avalanche = function() {
return Bodies.circle(x, y, Common.random(10, 20), { friction: 0.00001, restitution: 0.5, density: 0.001 }); return Bodies.circle(x, y, Common.random(10, 20), { friction: 0.00001, restitution: 0.5, density: 0.001 });
}); });
World.add(world, stack); Composite.add(world, stack);
World.add(world, [ Composite.add(world, [
Bodies.rectangle(200, 150, 700, 20, { isStatic: true, angle: Math.PI * 0.06, render: { fillStyle: '#060a19' } }), Bodies.rectangle(200, 150, 700, 20, { isStatic: true, angle: Math.PI * 0.06, render: { fillStyle: '#060a19' } }),
Bodies.rectangle(500, 350, 700, 20, { isStatic: true, angle: -Math.PI * 0.06, render: { fillStyle: '#060a19' } }), Bodies.rectangle(500, 350, 700, 20, { isStatic: true, angle: -Math.PI * 0.06, render: { fillStyle: '#060a19' } }),
Bodies.rectangle(340, 580, 700, 20, { isStatic: true, angle: Math.PI * 0.04, render: { fillStyle: '#060a19' } }) Bodies.rectangle(340, 580, 700, 20, { isStatic: true, angle: Math.PI * 0.04, render: { fillStyle: '#060a19' } })
@ -70,7 +69,7 @@ Example.avalanche = function() {
} }
}); });
World.add(world, mouseConstraint); Composite.add(world, mouseConstraint);
// keep the mouse in sync with rendering // keep the mouse in sync with rendering
render.mouse = mouse; render.mouse = mouse;

View file

@ -21,7 +21,6 @@ Example.ballPool = function() {
Common = Matter.Common, Common = Matter.Common,
MouseConstraint = Matter.MouseConstraint, MouseConstraint = Matter.MouseConstraint,
Mouse = Matter.Mouse, Mouse = Matter.Mouse,
World = Matter.World,
Bodies = Matter.Bodies; Bodies = Matter.Bodies;
// create engine // create engine
@ -46,7 +45,7 @@ Example.ballPool = function() {
Runner.run(runner, engine); Runner.run(runner, engine);
// add bodies // add bodies
World.add(world, [ Composite.add(world, [
Bodies.rectangle(400, 600, 1200, 50.5, { isStatic: true, render: { fillStyle: '#060a19' } }) Bodies.rectangle(400, 600, 1200, 50.5, { isStatic: true, render: { fillStyle: '#060a19' } })
]); ]);
@ -54,7 +53,7 @@ Example.ballPool = function() {
return Bodies.circle(x, y, Common.random(15, 30), { restitution: 0.6, friction: 0.1 }); return Bodies.circle(x, y, Common.random(15, 30), { restitution: 0.6, friction: 0.1 });
}); });
World.add(world, [ Composite.add(world, [
stack, stack,
Bodies.polygon(200, 460, 3, 60), Bodies.polygon(200, 460, 3, 60),
Bodies.polygon(400, 460, 5, 60), Bodies.polygon(400, 460, 5, 60),
@ -73,7 +72,7 @@ Example.ballPool = function() {
} }
}); });
World.add(world, mouseConstraint); Composite.add(world, mouseConstraint);
// keep the mouse in sync with rendering // keep the mouse in sync with rendering
render.mouse = mouse; render.mouse = mouse;

View file

@ -10,7 +10,7 @@ Example.bridge = function() {
Constraint = Matter.Constraint, Constraint = Matter.Constraint,
MouseConstraint = Matter.MouseConstraint, MouseConstraint = Matter.MouseConstraint,
Mouse = Matter.Mouse, Mouse = Matter.Mouse,
World = Matter.World, Composite = Matter.Composite,
Bodies = Matter.Bodies; Bodies = Matter.Bodies;
// create engine // create engine
@ -61,7 +61,7 @@ Example.bridge = function() {
return Bodies.rectangle(x, y, 50, 50, Common.random(20, 40)); return Bodies.rectangle(x, y, 50, 50, Common.random(20, 40));
}); });
World.add(world, [ Composite.add(world, [
bridge, bridge,
stack, stack,
Bodies.rectangle(30, 490, 220, 380, { Bodies.rectangle(30, 490, 220, 380, {
@ -100,7 +100,7 @@ Example.bridge = function() {
} }
}); });
World.add(world, mouseConstraint); Composite.add(world, mouseConstraint);
// keep the mouse in sync with rendering // keep the mouse in sync with rendering
render.mouse = mouse; render.mouse = mouse;

View file

@ -8,7 +8,7 @@ Example.broadphase = function() {
Common = Matter.Common, Common = Matter.Common,
MouseConstraint = Matter.MouseConstraint, MouseConstraint = Matter.MouseConstraint,
Mouse = Matter.Mouse, Mouse = Matter.Mouse,
World = Matter.World, Composite = Matter.Composite,
Bodies = Matter.Bodies; Bodies = Matter.Bodies;
// create engine // create engine
@ -34,7 +34,7 @@ Example.broadphase = function() {
Runner.run(runner, engine); Runner.run(runner, engine);
// add bodies // add bodies
World.add(world, [ Composite.add(world, [
// walls // walls
Bodies.rectangle(400, 0, 800, 50, { isStatic: true }), Bodies.rectangle(400, 0, 800, 50, { isStatic: true }),
Bodies.rectangle(400, 600, 800, 50, { isStatic: true }), Bodies.rectangle(400, 600, 800, 50, { isStatic: true }),
@ -57,7 +57,7 @@ Example.broadphase = function() {
} }
}); });
World.add(world, stack); Composite.add(world, stack);
// add mouse control // add mouse control
var mouse = Mouse.create(render.canvas), var mouse = Mouse.create(render.canvas),
@ -71,7 +71,7 @@ Example.broadphase = function() {
} }
}); });
World.add(world, mouseConstraint); Composite.add(world, mouseConstraint);
// keep the mouse in sync with rendering // keep the mouse in sync with rendering
render.mouse = mouse; render.mouse = mouse;

View file

@ -7,7 +7,7 @@ Example.car = function() {
Composites = Matter.Composites, Composites = Matter.Composites,
MouseConstraint = Matter.MouseConstraint, MouseConstraint = Matter.MouseConstraint,
Mouse = Matter.Mouse, Mouse = Matter.Mouse,
World = Matter.World, Composite = Matter.Composite,
Bodies = Matter.Bodies; Bodies = Matter.Bodies;
// create engine // create engine
@ -33,7 +33,7 @@ Example.car = function() {
Runner.run(runner, engine); Runner.run(runner, engine);
// add bodies // add bodies
World.add(world, [ Composite.add(world, [
// walls // walls
Bodies.rectangle(400, 0, 800, 50, { isStatic: true }), Bodies.rectangle(400, 0, 800, 50, { isStatic: true }),
Bodies.rectangle(400, 600, 800, 50, { isStatic: true }), Bodies.rectangle(400, 600, 800, 50, { isStatic: true }),
@ -43,12 +43,12 @@ Example.car = function() {
// see car function defined later in this file // see car function defined later in this file
var scale = 0.9; var scale = 0.9;
World.add(world, Example.car.car(150, 100, 150 * scale, 30 * scale, 30 * scale)); Composite.add(world, Example.car.car(150, 100, 150 * scale, 30 * scale, 30 * scale));
scale = 0.8; scale = 0.8;
World.add(world, Example.car.car(350, 300, 150 * scale, 30 * scale, 30 * scale)); Composite.add(world, Example.car.car(350, 300, 150 * scale, 30 * scale, 30 * scale));
World.add(world, [ Composite.add(world, [
Bodies.rectangle(200, 150, 400, 20, { isStatic: true, angle: Math.PI * 0.06, render: { fillStyle: '#060a19' }}), Bodies.rectangle(200, 150, 400, 20, { isStatic: true, angle: Math.PI * 0.06, render: { fillStyle: '#060a19' }}),
Bodies.rectangle(500, 350, 650, 20, { isStatic: true, angle: -Math.PI * 0.06, render: { fillStyle: '#060a19' }}), Bodies.rectangle(500, 350, 650, 20, { isStatic: true, angle: -Math.PI * 0.06, render: { fillStyle: '#060a19' }}),
Bodies.rectangle(300, 560, 600, 20, { isStatic: true, angle: Math.PI * 0.04, render: { fillStyle: '#060a19' }}) Bodies.rectangle(300, 560, 600, 20, { isStatic: true, angle: Math.PI * 0.04, render: { fillStyle: '#060a19' }})
@ -66,7 +66,7 @@ Example.car = function() {
} }
}); });
World.add(world, mouseConstraint); Composite.add(world, mouseConstraint);
// keep the mouse in sync with rendering // keep the mouse in sync with rendering
render.mouse = mouse; render.mouse = mouse;

View file

@ -8,7 +8,7 @@ Example.catapult = function() {
Constraint = Matter.Constraint, Constraint = Matter.Constraint,
MouseConstraint = Matter.MouseConstraint, MouseConstraint = Matter.MouseConstraint,
Mouse = Matter.Mouse, Mouse = Matter.Mouse,
World = Matter.World, Composite = Matter.Composite,
Bodies = Matter.Bodies, Bodies = Matter.Bodies,
Body = Matter.Body, Body = Matter.Body,
Vector = Matter.Vector; Vector = Matter.Vector;
@ -45,7 +45,7 @@ Example.catapult = function() {
var catapult = Bodies.rectangle(400, 520, 320, 20, { collisionFilter: { group: group } }); var catapult = Bodies.rectangle(400, 520, 320, 20, { collisionFilter: { group: group } });
World.add(world, [ Composite.add(world, [
stack, stack,
catapult, catapult,
Bodies.rectangle(400, 600, 800, 50.5, { isStatic: true, render: { fillStyle: '#060a19' } }), Bodies.rectangle(400, 600, 800, 50.5, { isStatic: true, render: { fillStyle: '#060a19' } }),
@ -72,7 +72,7 @@ Example.catapult = function() {
} }
}); });
World.add(world, mouseConstraint); Composite.add(world, mouseConstraint);
// keep the mouse in sync with rendering // keep the mouse in sync with rendering
render.mouse = mouse; render.mouse = mouse;

View file

@ -10,7 +10,6 @@ Example.chains = function() {
Constraint = Matter.Constraint, Constraint = Matter.Constraint,
MouseConstraint = Matter.MouseConstraint, MouseConstraint = Matter.MouseConstraint,
Mouse = Matter.Mouse, Mouse = Matter.Mouse,
World = Matter.World,
Bodies = Matter.Bodies; Bodies = Matter.Bodies;
// create engine // create engine
@ -79,7 +78,7 @@ Example.chains = function() {
stiffness: 0.5 stiffness: 0.5
})); }));
World.add(world, [ Composite.add(world, [
ropeA, ropeA,
ropeB, ropeB,
ropeC, ropeC,
@ -98,7 +97,7 @@ Example.chains = function() {
} }
}); });
World.add(world, mouseConstraint); Composite.add(world, mouseConstraint);
// keep the mouse in sync with rendering // keep the mouse in sync with rendering
render.mouse = mouse; render.mouse = mouse;

View file

@ -7,7 +7,7 @@ Example.circleStack = function() {
Composites = Matter.Composites, Composites = Matter.Composites,
MouseConstraint = Matter.MouseConstraint, MouseConstraint = Matter.MouseConstraint,
Mouse = Matter.Mouse, Mouse = Matter.Mouse,
World = Matter.World, Composite = Matter.Composite,
Bodies = Matter.Bodies; Bodies = Matter.Bodies;
// create engine // create engine
@ -36,7 +36,7 @@ Example.circleStack = function() {
return Bodies.circle(x, y, 20); return Bodies.circle(x, y, 20);
}); });
World.add(world, [ Composite.add(world, [
// walls // walls
Bodies.rectangle(400, 0, 800, 50, { isStatic: true }), Bodies.rectangle(400, 0, 800, 50, { isStatic: true }),
Bodies.rectangle(400, 600, 800, 50, { isStatic: true }), Bodies.rectangle(400, 600, 800, 50, { isStatic: true }),
@ -57,7 +57,7 @@ Example.circleStack = function() {
} }
}); });
World.add(world, mouseConstraint); Composite.add(world, mouseConstraint);
// keep the mouse in sync with rendering // keep the mouse in sync with rendering
render.mouse = mouse; render.mouse = mouse;

View file

@ -8,7 +8,7 @@ Example.cloth = function() {
Composites = Matter.Composites, Composites = Matter.Composites,
MouseConstraint = Matter.MouseConstraint, MouseConstraint = Matter.MouseConstraint,
Mouse = Matter.Mouse, Mouse = Matter.Mouse,
World = Matter.World, Composite = Matter.Composite,
Bodies = Matter.Bodies; Bodies = Matter.Bodies;
// create engine // create engine
@ -38,7 +38,7 @@ Example.cloth = function() {
cloth.bodies[i].isStatic = true; cloth.bodies[i].isStatic = true;
} }
World.add(world, [ Composite.add(world, [
cloth, cloth,
Bodies.circle(300, 500, 80, { isStatic: true, render: { fillStyle: '#060a19' }}), Bodies.circle(300, 500, 80, { isStatic: true, render: { fillStyle: '#060a19' }}),
Bodies.rectangle(500, 480, 80, 80, { isStatic: true, render: { fillStyle: '#060a19' }}), Bodies.rectangle(500, 480, 80, 80, { isStatic: true, render: { fillStyle: '#060a19' }}),
@ -57,7 +57,7 @@ Example.cloth = function() {
} }
}); });
World.add(world, mouseConstraint); Composite.add(world, mouseConstraint);
// keep the mouse in sync with rendering // keep the mouse in sync with rendering
render.mouse = mouse; render.mouse = mouse;

View file

@ -9,7 +9,6 @@ Example.collisionFiltering = function() {
Common = Matter.Common, Common = Matter.Common,
MouseConstraint = Matter.MouseConstraint, MouseConstraint = Matter.MouseConstraint,
Mouse = Matter.Mouse, Mouse = Matter.Mouse,
World = Matter.World,
Bodies = Matter.Bodies; Bodies = Matter.Bodies;
// create engine // create engine
@ -44,7 +43,7 @@ Example.collisionFiltering = function() {
colorC = '#f5d259'; colorC = '#f5d259';
// add floor // add floor
World.add(world, Bodies.rectangle(400, 600, 900, 50, { Composite.add(world, Bodies.rectangle(400, 600, 900, 50, {
isStatic: true, isStatic: true,
render: { render: {
fillStyle: 'transparent', fillStyle: 'transparent',
@ -53,7 +52,7 @@ Example.collisionFiltering = function() {
})); }));
// create a stack with varying body categories (but these bodies can all collide with each other) // create a stack with varying body categories (but these bodies can all collide with each other)
World.add(world, Composite.add(world,
Composites.stack(275, 100, 5, 9, 10, 10, function(x, y, column, row) { Composites.stack(275, 100, 5, 9, 10, 10, function(x, y, column, row) {
var category = redCategory, var category = redCategory,
color = colorA; color = colorA;
@ -80,7 +79,7 @@ Example.collisionFiltering = function() {
); );
// this body will only collide with the walls and the green bodies // this body will only collide with the walls and the green bodies
World.add(world, Composite.add(world,
Bodies.circle(310, 40, 30, { Bodies.circle(310, 40, 30, {
collisionFilter: { collisionFilter: {
mask: defaultCategory | greenCategory mask: defaultCategory | greenCategory
@ -92,7 +91,7 @@ Example.collisionFiltering = function() {
); );
// this body will only collide with the walls and the red bodies // this body will only collide with the walls and the red bodies
World.add(world, Composite.add(world,
Bodies.circle(400, 40, 30, { Bodies.circle(400, 40, 30, {
collisionFilter: { collisionFilter: {
mask: defaultCategory | redCategory mask: defaultCategory | redCategory
@ -104,7 +103,7 @@ Example.collisionFiltering = function() {
); );
// this body will only collide with the walls and the blue bodies // this body will only collide with the walls and the blue bodies
World.add(world, Composite.add(world,
Bodies.circle(480, 40, 30, { Bodies.circle(480, 40, 30, {
collisionFilter: { collisionFilter: {
mask: defaultCategory | blueCategory mask: defaultCategory | blueCategory
@ -127,7 +126,7 @@ Example.collisionFiltering = function() {
} }
}); });
World.add(world, mouseConstraint); Composite.add(world, mouseConstraint);
// keep the mouse in sync with rendering // keep the mouse in sync with rendering
render.mouse = mouse; render.mouse = mouse;

View file

@ -9,7 +9,6 @@ Example.compositeManipulation = function() {
Composites = Matter.Composites, Composites = Matter.Composites,
MouseConstraint = Matter.MouseConstraint, MouseConstraint = Matter.MouseConstraint,
Mouse = Matter.Mouse, Mouse = Matter.Mouse,
World = Matter.World,
Bodies = Matter.Bodies; Bodies = Matter.Bodies;
// create engine // create engine
@ -34,7 +33,7 @@ Example.compositeManipulation = function() {
Runner.run(runner, engine); Runner.run(runner, engine);
// add bodies // add bodies
World.add(world, [ Composite.add(world, [
// walls // walls
Bodies.rectangle(400, 0, 800, 50, { isStatic: true }), Bodies.rectangle(400, 0, 800, 50, { isStatic: true }),
Bodies.rectangle(400, 600, 800, 50, { isStatic: true }), Bodies.rectangle(400, 600, 800, 50, { isStatic: true }),
@ -46,7 +45,7 @@ Example.compositeManipulation = function() {
return Bodies.rectangle(x, y, 40, 40); return Bodies.rectangle(x, y, 40, 40);
}); });
World.add(world, stack); Composite.add(world, stack);
world.gravity.y = 0; world.gravity.y = 0;
@ -83,7 +82,7 @@ Example.compositeManipulation = function() {
} }
}); });
World.add(world, mouseConstraint); Composite.add(world, mouseConstraint);
// keep the mouse in sync with rendering // keep the mouse in sync with rendering
render.mouse = mouse; render.mouse = mouse;

View file

@ -6,9 +6,9 @@ Example.compound = function() {
Runner = Matter.Runner, Runner = Matter.Runner,
Body = Matter.Body, Body = Matter.Body,
Constraint = Matter.Constraint, Constraint = Matter.Constraint,
Composite = Matter.Composite,
MouseConstraint = Matter.MouseConstraint, MouseConstraint = Matter.MouseConstraint,
Mouse = Matter.Mouse, Mouse = Matter.Mouse,
World = Matter.World,
Bodies = Matter.Bodies; Bodies = Matter.Bodies;
// create engine // create engine
@ -63,7 +63,7 @@ Example.compound = function() {
pointB: { x: 0, y: 0 } pointB: { x: 0, y: 0 }
}); });
World.add(world, [ Composite.add(world, [
compoundBodyA, compoundBodyA,
compoundBodyB, compoundBodyB,
constraint, constraint,
@ -82,7 +82,7 @@ Example.compound = function() {
} }
}); });
World.add(world, mouseConstraint); Composite.add(world, mouseConstraint);
// keep the mouse in sync with rendering // keep the mouse in sync with rendering
render.mouse = mouse; render.mouse = mouse;

View file

@ -8,7 +8,7 @@ Example.compoundStack = function() {
Composites = Matter.Composites, Composites = Matter.Composites,
MouseConstraint = Matter.MouseConstraint, MouseConstraint = Matter.MouseConstraint,
Mouse = Matter.Mouse, Mouse = Matter.Mouse,
World = Matter.World, Composite = Matter.Composite,
Bodies = Matter.Bodies; Bodies = Matter.Bodies;
// create engine // create engine
@ -44,7 +44,7 @@ Example.compoundStack = function() {
}); });
}); });
World.add(world, [ Composite.add(world, [
stack, stack,
// walls // walls
Bodies.rectangle(400, 0, 800, 50, { isStatic: true }), Bodies.rectangle(400, 0, 800, 50, { isStatic: true }),
@ -65,7 +65,7 @@ Example.compoundStack = function() {
} }
}); });
World.add(world, mouseConstraint); Composite.add(world, mouseConstraint);
// keep the mouse in sync with rendering // keep the mouse in sync with rendering
render.mouse = mouse; render.mouse = mouse;

View file

@ -8,7 +8,7 @@ Example.concave = function() {
Common = Matter.Common, Common = Matter.Common,
MouseConstraint = Matter.MouseConstraint, MouseConstraint = Matter.MouseConstraint,
Mouse = Matter.Mouse, Mouse = Matter.Mouse,
World = Matter.World, Composite = Matter.Composite,
Vertices = Matter.Vertices, Vertices = Matter.Vertices,
Bodies = Matter.Bodies; Bodies = Matter.Bodies;
@ -36,7 +36,7 @@ Example.concave = function() {
Runner.run(runner, engine); Runner.run(runner, engine);
// add bodies // add bodies
World.add(world, [ Composite.add(world, [
// walls // walls
Bodies.rectangle(400, 0, 800, 50, { isStatic: true }), Bodies.rectangle(400, 0, 800, 50, { isStatic: true }),
Bodies.rectangle(400, 600, 800, 50, { isStatic: true }), Bodies.rectangle(400, 600, 800, 50, { isStatic: true }),
@ -60,7 +60,7 @@ Example.concave = function() {
}, true); }, true);
}); });
World.add(world, stack); Composite.add(world, stack);
// add mouse control // add mouse control
var mouse = Mouse.create(render.canvas), var mouse = Mouse.create(render.canvas),
@ -74,7 +74,7 @@ Example.concave = function() {
} }
}); });
World.add(world, mouseConstraint); Composite.add(world, mouseConstraint);
// keep the mouse in sync with rendering // keep the mouse in sync with rendering
render.mouse = mouse; render.mouse = mouse;

View file

@ -9,7 +9,7 @@ Example.constraints = function() {
Constraint = Matter.Constraint, Constraint = Matter.Constraint,
MouseConstraint = Matter.MouseConstraint, MouseConstraint = Matter.MouseConstraint,
Mouse = Matter.Mouse, Mouse = Matter.Mouse,
World = Matter.World, Composite = Matter.Composite,
Bodies = Matter.Bodies; Bodies = Matter.Bodies;
// create engine // create engine
@ -42,7 +42,7 @@ Example.constraints = function() {
pointB: { x: -10, y: -10 } pointB: { x: -10, y: -10 }
}); });
World.add(world, [body, constraint]); Composite.add(world, [body, constraint]);
// add soft global constraint // add soft global constraint
var body = Bodies.polygon(280, 100, 3, 30); var body = Bodies.polygon(280, 100, 3, 30);
@ -54,7 +54,7 @@ Example.constraints = function() {
stiffness: 0.001 stiffness: 0.001
}); });
World.add(world, [body, constraint]); Composite.add(world, [body, constraint]);
// add damped soft global constraint // add damped soft global constraint
var body = Bodies.polygon(400, 100, 4, 30); var body = Bodies.polygon(400, 100, 4, 30);
@ -67,7 +67,7 @@ Example.constraints = function() {
damping: 0.05 damping: 0.05
}); });
World.add(world, [body, constraint]); Composite.add(world, [body, constraint]);
// add revolute constraint // add revolute constraint
var body = Bodies.rectangle(600, 200, 200, 20); var body = Bodies.rectangle(600, 200, 200, 20);
@ -79,7 +79,7 @@ Example.constraints = function() {
length: 0 length: 0
}); });
World.add(world, [body, ball, constraint]); Composite.add(world, [body, ball, constraint]);
// add revolute multi-body constraint // add revolute multi-body constraint
var body = Bodies.rectangle(500, 400, 100, 20, { collisionFilter: { group: -1 } }); var body = Bodies.rectangle(500, 400, 100, 20, { collisionFilter: { group: -1 } });
@ -90,7 +90,7 @@ Example.constraints = function() {
bodyB: ball bodyB: ball
}); });
World.add(world, [body, ball, constraint]); Composite.add(world, [body, ball, constraint]);
// add stiff multi-body constraint // add stiff multi-body constraint
var bodyA = Bodies.polygon(100, 400, 6, 20); var bodyA = Bodies.polygon(100, 400, 6, 20);
@ -103,7 +103,7 @@ Example.constraints = function() {
pointB: { x: -10, y: -10 } pointB: { x: -10, y: -10 }
}); });
World.add(world, [bodyA, bodyB, constraint]); Composite.add(world, [bodyA, bodyB, constraint]);
// add soft global constraint // add soft global constraint
var bodyA = Bodies.polygon(300, 400, 4, 20); var bodyA = Bodies.polygon(300, 400, 4, 20);
@ -117,7 +117,7 @@ Example.constraints = function() {
stiffness: 0.001 stiffness: 0.001
}); });
World.add(world, [bodyA, bodyB, constraint]); Composite.add(world, [bodyA, bodyB, constraint]);
// add damped soft global constraint // add damped soft global constraint
var bodyA = Bodies.polygon(500, 400, 6, 30); var bodyA = Bodies.polygon(500, 400, 6, 30);
@ -132,9 +132,9 @@ Example.constraints = function() {
damping: 0.1 damping: 0.1
}); });
World.add(world, [bodyA, bodyB, constraint]); Composite.add(world, [bodyA, bodyB, constraint]);
World.add(world, [ Composite.add(world, [
// walls // walls
Bodies.rectangle(400, 0, 800, 50, { isStatic: true }), Bodies.rectangle(400, 0, 800, 50, { isStatic: true }),
Bodies.rectangle(400, 600, 800, 50, { isStatic: true }), Bodies.rectangle(400, 600, 800, 50, { isStatic: true }),
@ -155,7 +155,7 @@ Example.constraints = function() {
} }
}); });
World.add(world, mouseConstraint); Composite.add(world, mouseConstraint);
// keep the mouse in sync with rendering // keep the mouse in sync with rendering
render.mouse = mouse; render.mouse = mouse;

View file

@ -11,7 +11,6 @@ Example.doublePendulum = function() {
Constraint = Matter.Constraint, Constraint = Matter.Constraint,
MouseConstraint = Matter.MouseConstraint, MouseConstraint = Matter.MouseConstraint,
Mouse = Matter.Mouse, Mouse = Matter.Mouse,
World = Matter.World,
Bodies = Matter.Bodies, Bodies = Matter.Bodies,
Vector = Matter.Vector; Vector = Matter.Vector;
@ -82,7 +81,7 @@ Example.doublePendulum = function() {
y: lowerArm.position.y y: lowerArm.position.y
}); });
World.add(world, pendulum); Composite.add(world, pendulum);
var trail = []; var trail = [];
@ -124,7 +123,7 @@ Example.doublePendulum = function() {
} }
}); });
World.add(world, mouseConstraint); Composite.add(world, mouseConstraint);
// keep the mouse in sync with rendering // keep the mouse in sync with rendering
render.mouse = mouse; render.mouse = mouse;

View file

@ -11,7 +11,6 @@ Example.events = function() {
Common = Matter.Common, Common = Matter.Common,
MouseConstraint = Matter.MouseConstraint, MouseConstraint = Matter.MouseConstraint,
Mouse = Matter.Mouse, Mouse = Matter.Mouse,
World = Matter.World,
Bodies = Matter.Bodies; Bodies = Matter.Bodies;
// create engine // create engine
@ -89,7 +88,7 @@ Example.events = function() {
var bodyStyle = { fillStyle: '#222' }; var bodyStyle = { fillStyle: '#222' };
// scene code // scene code
World.add(world, [ Composite.add(world, [
Bodies.rectangle(400, 0, 800, 50, { isStatic: true, render: bodyStyle }), Bodies.rectangle(400, 0, 800, 50, { isStatic: true, render: bodyStyle }),
Bodies.rectangle(400, 600, 800, 50, { isStatic: true, render: bodyStyle }), Bodies.rectangle(400, 600, 800, 50, { isStatic: true, render: bodyStyle }),
Bodies.rectangle(800, 300, 50, 600, { isStatic: true, render: bodyStyle }), Bodies.rectangle(800, 300, 50, 600, { isStatic: true, render: bodyStyle }),
@ -100,7 +99,7 @@ Example.events = function() {
return Bodies.circle(x, y, 15, { restitution: 1, render: bodyStyle }); return Bodies.circle(x, y, 15, { restitution: 1, render: bodyStyle });
}); });
World.add(world, stack); Composite.add(world, stack);
var shakeScene = function(engine) { var shakeScene = function(engine) {
var bodies = Composite.allBodies(engine.world); var bodies = Composite.allBodies(engine.world);
@ -131,7 +130,7 @@ Example.events = function() {
} }
}); });
World.add(world, mouseConstraint); Composite.add(world, mouseConstraint);
// keep the mouse in sync with rendering // keep the mouse in sync with rendering
render.mouse = mouse; render.mouse = mouse;

View file

@ -6,7 +6,7 @@ Example.friction = function() {
Runner = Matter.Runner, Runner = Matter.Runner,
MouseConstraint = Matter.MouseConstraint, MouseConstraint = Matter.MouseConstraint,
Mouse = Matter.Mouse, Mouse = Matter.Mouse,
World = Matter.World, Composite = Matter.Composite,
Bodies = Matter.Bodies; Bodies = Matter.Bodies;
// create engine // create engine
@ -31,7 +31,7 @@ Example.friction = function() {
Runner.run(runner, engine); Runner.run(runner, engine);
// add bodies // add bodies
World.add(world, [ Composite.add(world, [
// walls // walls
Bodies.rectangle(400, 0, 800, 50, { isStatic: true }), Bodies.rectangle(400, 0, 800, 50, { isStatic: true }),
Bodies.rectangle(400, 600, 800, 50, { isStatic: true }), Bodies.rectangle(400, 600, 800, 50, { isStatic: true }),
@ -39,17 +39,17 @@ Example.friction = function() {
Bodies.rectangle(0, 300, 50, 600, { isStatic: true }) Bodies.rectangle(0, 300, 50, 600, { isStatic: true })
]); ]);
World.add(world, [ Composite.add(world, [
Bodies.rectangle(300, 180, 700, 20, { isStatic: true, angle: Math.PI * 0.06, render: { fillStyle: '#060a19' } }), Bodies.rectangle(300, 180, 700, 20, { isStatic: true, angle: Math.PI * 0.06, render: { fillStyle: '#060a19' } }),
Bodies.rectangle(300, 70, 40, 40, { friction: 0.001 }) Bodies.rectangle(300, 70, 40, 40, { friction: 0.001 })
]); ]);
World.add(world, [ Composite.add(world, [
Bodies.rectangle(300, 350, 700, 20, { isStatic: true, angle: Math.PI * 0.06, render: { fillStyle: '#060a19' } }), Bodies.rectangle(300, 350, 700, 20, { isStatic: true, angle: Math.PI * 0.06, render: { fillStyle: '#060a19' } }),
Bodies.rectangle(300, 250, 40, 40, { friction: 0.0005 }) Bodies.rectangle(300, 250, 40, 40, { friction: 0.0005 })
]); ]);
World.add(world, [ Composite.add(world, [
Bodies.rectangle(300, 520, 700, 20, { isStatic: true, angle: Math.PI * 0.06, render: { fillStyle: '#060a19' } }), Bodies.rectangle(300, 520, 700, 20, { isStatic: true, angle: Math.PI * 0.06, render: { fillStyle: '#060a19' } }),
Bodies.rectangle(300, 430, 40, 40, { friction: 0 }) Bodies.rectangle(300, 430, 40, 40, { friction: 0 })
]); ]);
@ -66,7 +66,7 @@ Example.friction = function() {
} }
}); });
World.add(world, mouseConstraint); Composite.add(world, mouseConstraint);
// keep the mouse in sync with rendering // keep the mouse in sync with rendering
render.mouse = mouse; render.mouse = mouse;

View file

@ -8,7 +8,7 @@ Example.gravity = function() {
Common = Matter.Common, Common = Matter.Common,
MouseConstraint = Matter.MouseConstraint, MouseConstraint = Matter.MouseConstraint,
Mouse = Matter.Mouse, Mouse = Matter.Mouse,
World = Matter.World, Composite = Matter.Composite,
Bodies = Matter.Bodies; Bodies = Matter.Bodies;
// create engine // create engine
@ -34,7 +34,7 @@ Example.gravity = function() {
Runner.run(runner, engine); Runner.run(runner, engine);
// add bodies // add bodies
World.add(world, [ Composite.add(world, [
Bodies.rectangle(400, 0, 800, 50, { isStatic: true }), Bodies.rectangle(400, 0, 800, 50, { isStatic: true }),
Bodies.rectangle(400, 600, 800, 50.5, { isStatic: true }), Bodies.rectangle(400, 600, 800, 50.5, { isStatic: true }),
Bodies.rectangle(800, 300, 50, 600, { isStatic: true }), Bodies.rectangle(800, 300, 50, 600, { isStatic: true }),
@ -58,7 +58,7 @@ Example.gravity = function() {
} }
}); });
World.add(world, stack); Composite.add(world, stack);
// add mouse control // add mouse control
var mouse = Mouse.create(render.canvas), var mouse = Mouse.create(render.canvas),
@ -72,7 +72,7 @@ Example.gravity = function() {
} }
}); });
World.add(world, mouseConstraint); Composite.add(world, mouseConstraint);
// keep the mouse in sync with rendering // keep the mouse in sync with rendering
render.mouse = mouse; render.mouse = mouse;

View file

@ -8,7 +8,7 @@ Example.gyro = function() {
Common = Matter.Common, Common = Matter.Common,
MouseConstraint = Matter.MouseConstraint, MouseConstraint = Matter.MouseConstraint,
Mouse = Matter.Mouse, Mouse = Matter.Mouse,
World = Matter.World, Composite = Matter.Composite,
Bodies = Matter.Bodies; Bodies = Matter.Bodies;
// create engine // create engine
@ -59,7 +59,7 @@ Example.gyro = function() {
} }
}); });
World.add(world, [ Composite.add(world, [
stack, stack,
Bodies.rectangle(400, 0, 800, 50, { isStatic: true }), Bodies.rectangle(400, 0, 800, 50, { isStatic: true }),
Bodies.rectangle(400, 600, 800, 50, { isStatic: true }), Bodies.rectangle(400, 600, 800, 50, { isStatic: true }),
@ -103,7 +103,7 @@ Example.gyro = function() {
} }
}); });
World.add(world, mouseConstraint); Composite.add(world, mouseConstraint);
// keep the mouse in sync with rendering // keep the mouse in sync with rendering
render.mouse = mouse; render.mouse = mouse;

View file

@ -8,7 +8,7 @@ Example.manipulation = function() {
Events = Matter.Events, Events = Matter.Events,
MouseConstraint = Matter.MouseConstraint, MouseConstraint = Matter.MouseConstraint,
Mouse = Matter.Mouse, Mouse = Matter.Mouse,
World = Matter.World, Composite = Matter.Composite,
Bodies = Matter.Bodies; Bodies = Matter.Bodies;
// create engine // create engine
@ -49,9 +49,9 @@ Example.manipulation = function() {
isStatic: true isStatic: true
}); });
World.add(world, [bodyA, bodyB, bodyC, bodyD, bodyE, bodyF, bodyG, compound]); Composite.add(world, [bodyA, bodyB, bodyC, bodyD, bodyE, bodyF, bodyG, compound]);
World.add(world, [ Composite.add(world, [
// walls // walls
Bodies.rectangle(400, 0, 800, 50, { isStatic: true }), Bodies.rectangle(400, 0, 800, 50, { isStatic: true }),
Bodies.rectangle(400, 600, 800, 50, { isStatic: true }), Bodies.rectangle(400, 600, 800, 50, { isStatic: true }),
@ -116,7 +116,7 @@ Example.manipulation = function() {
} }
}); });
World.add(world, mouseConstraint); Composite.add(world, mouseConstraint);
// keep the mouse in sync with rendering // keep the mouse in sync with rendering
render.mouse = mouse; render.mouse = mouse;

View file

@ -8,7 +8,7 @@ Example.mixed = function() {
Common = Matter.Common, Common = Matter.Common,
MouseConstraint = Matter.MouseConstraint, MouseConstraint = Matter.MouseConstraint,
Mouse = Matter.Mouse, Mouse = Matter.Mouse,
World = Matter.World, Composite = Matter.Composite,
Bodies = Matter.Bodies; Bodies = Matter.Bodies;
// create engine // create engine
@ -59,9 +59,9 @@ Example.mixed = function() {
} }
}); });
World.add(world, stack); Composite.add(world, stack);
World.add(world, [ Composite.add(world, [
// walls // walls
Bodies.rectangle(400, 0, 800, 50, { isStatic: true }), Bodies.rectangle(400, 0, 800, 50, { isStatic: true }),
Bodies.rectangle(400, 600, 800, 50, { isStatic: true }), Bodies.rectangle(400, 600, 800, 50, { isStatic: true }),
@ -81,7 +81,7 @@ Example.mixed = function() {
} }
}); });
World.add(world, mouseConstraint); Composite.add(world, mouseConstraint);
// keep the mouse in sync with rendering // keep the mouse in sync with rendering
render.mouse = mouse; render.mouse = mouse;

View file

@ -8,7 +8,7 @@ Example.newtonsCradle = function() {
Composites = Matter.Composites, Composites = Matter.Composites,
MouseConstraint = Matter.MouseConstraint, MouseConstraint = Matter.MouseConstraint,
Mouse = Matter.Mouse, Mouse = Matter.Mouse,
World = Matter.World; Composite = Matter.Composite;
// create engine // create engine
var engine = Engine.create(), var engine = Engine.create(),
@ -33,11 +33,11 @@ Example.newtonsCradle = function() {
// see newtonsCradle function defined later in this file // see newtonsCradle function defined later in this file
var cradle = Example.newtonsCradle.newtonsCradle(280, 100, 5, 30, 200); var cradle = Example.newtonsCradle.newtonsCradle(280, 100, 5, 30, 200);
World.add(world, cradle); Composite.add(world, cradle);
Body.translate(cradle.bodies[0], { x: -180, y: -100 }); Body.translate(cradle.bodies[0], { x: -180, y: -100 });
cradle = Example.newtonsCradle.newtonsCradle(280, 380, 7, 20, 140); cradle = Example.newtonsCradle.newtonsCradle(280, 380, 7, 20, 140);
World.add(world, cradle); Composite.add(world, cradle);
Body.translate(cradle.bodies[0], { x: -140, y: -100 }); Body.translate(cradle.bodies[0], { x: -140, y: -100 });
// add mouse control // add mouse control
@ -52,7 +52,7 @@ Example.newtonsCradle = function() {
} }
}); });
World.add(world, mouseConstraint); Composite.add(world, mouseConstraint);
// keep the mouse in sync with rendering // keep the mouse in sync with rendering
render.mouse = mouse; render.mouse = mouse;

View file

@ -7,7 +7,7 @@ Example.pyramid = function() {
Composites = Matter.Composites, Composites = Matter.Composites,
MouseConstraint = Matter.MouseConstraint, MouseConstraint = Matter.MouseConstraint,
Mouse = Matter.Mouse, Mouse = Matter.Mouse,
World = Matter.World, Composite = Matter.Composite,
Bodies = Matter.Bodies; Bodies = Matter.Bodies;
// create engine // create engine
@ -36,7 +36,7 @@ Example.pyramid = function() {
return Bodies.rectangle(x, y, 40, 40); return Bodies.rectangle(x, y, 40, 40);
}); });
World.add(world, [ Composite.add(world, [
stack, stack,
// walls // walls
Bodies.rectangle(400, 0, 800, 50, { isStatic: true }), Bodies.rectangle(400, 0, 800, 50, { isStatic: true }),
@ -57,7 +57,7 @@ Example.pyramid = function() {
} }
}); });
World.add(world, mouseConstraint); Composite.add(world, mouseConstraint);
// keep the mouse in sync with rendering // keep the mouse in sync with rendering
render.mouse = mouse; render.mouse = mouse;

View file

@ -12,7 +12,6 @@ Example.ragdoll = function() {
Constraint = Matter.Constraint, Constraint = Matter.Constraint,
MouseConstraint = Matter.MouseConstraint, MouseConstraint = Matter.MouseConstraint,
Mouse = Matter.Mouse, Mouse = Matter.Mouse,
World = Matter.World,
Bodies = Matter.Bodies, Bodies = Matter.Bodies,
Vector = Matter.Vector; Vector = Matter.Vector;
@ -80,7 +79,7 @@ Example.ragdoll = function() {
Composite.add(ragdolls, ragdoll); Composite.add(ragdolls, ragdoll);
} }
World.add(world, [stack, obstacles, ragdolls]); Composite.add(world, [stack, obstacles, ragdolls]);
var timeScaleTarget = 1, var timeScaleTarget = 1,
counter = 0; counter = 0;
@ -173,7 +172,7 @@ Example.ragdoll = function() {
} }
}); });
World.add(world, mouseConstraint); Composite.add(world, mouseConstraint);
// keep the mouse in sync with rendering // keep the mouse in sync with rendering
render.mouse = mouse; render.mouse = mouse;

View file

@ -11,7 +11,6 @@ Example.raycasting = function() {
MouseConstraint = Matter.MouseConstraint, MouseConstraint = Matter.MouseConstraint,
Mouse = Matter.Mouse, Mouse = Matter.Mouse,
Events = Matter.Events, Events = Matter.Events,
World = Matter.World,
Vertices = Matter.Vertices, Vertices = Matter.Vertices,
Bodies = Matter.Bodies; Bodies = Matter.Bodies;
@ -59,7 +58,7 @@ Example.raycasting = function() {
var star = Vertices.fromPath('50 0 63 38 100 38 69 59 82 100 50 75 18 100 31 59 0 38 37 38'), var star = Vertices.fromPath('50 0 63 38 100 38 69 59 82 100 50 75 18 100 31 59 0 38 37 38'),
concave = Bodies.fromVertices(200, 200, star); concave = Bodies.fromVertices(200, 200, star);
World.add(world, [ Composite.add(world, [
stack, stack,
concave, concave,
// walls // walls
@ -114,7 +113,7 @@ Example.raycasting = function() {
} }
}); });
World.add(world, mouseConstraint); Composite.add(world, mouseConstraint);
// keep the mouse in sync with rendering // keep the mouse in sync with rendering
render.mouse = mouse; render.mouse = mouse;

View file

@ -6,7 +6,7 @@ Example.restitution = function() {
Runner = Matter.Runner, Runner = Matter.Runner,
MouseConstraint = Matter.MouseConstraint, MouseConstraint = Matter.MouseConstraint,
Mouse = Matter.Mouse, Mouse = Matter.Mouse,
World = Matter.World, Composite = Matter.Composite,
Bodies = Matter.Bodies; Bodies = Matter.Bodies;
// create engine // create engine
@ -36,7 +36,7 @@ Example.restitution = function() {
var rest = 0.9, var rest = 0.9,
space = 600 / 5; space = 600 / 5;
World.add(world, [ Composite.add(world, [
Bodies.rectangle(100 + space * 0, 150, 50, 50, { restitution: rest }), Bodies.rectangle(100 + space * 0, 150, 50, 50, { restitution: rest }),
Bodies.rectangle(100 + space * 1, 150, 50, 50, { restitution: rest, angle: -Math.PI * 0.15 }), Bodies.rectangle(100 + space * 1, 150, 50, 50, { restitution: rest, angle: -Math.PI * 0.15 }),
Bodies.rectangle(100 + space * 2, 150, 50, 50, { restitution: rest, angle: -Math.PI * 0.25 }), Bodies.rectangle(100 + space * 2, 150, 50, 50, { restitution: rest, angle: -Math.PI * 0.25 }),
@ -61,7 +61,7 @@ Example.restitution = function() {
} }
}); });
World.add(world, mouseConstraint); Composite.add(world, mouseConstraint);
// keep the mouse in sync with rendering // keep the mouse in sync with rendering
render.mouse = mouse; render.mouse = mouse;

View file

@ -6,7 +6,7 @@ Example.rounded = function() {
Runner = Matter.Runner, Runner = Matter.Runner,
MouseConstraint = Matter.MouseConstraint, MouseConstraint = Matter.MouseConstraint,
Mouse = Matter.Mouse, Mouse = Matter.Mouse,
World = Matter.World, Composite = Matter.Composite,
Bodies = Matter.Bodies; Bodies = Matter.Bodies;
// create engine // create engine
@ -31,7 +31,7 @@ Example.rounded = function() {
Runner.run(runner, engine); Runner.run(runner, engine);
// add bodies // add bodies
World.add(world, [ Composite.add(world, [
// walls // walls
Bodies.rectangle(400, 0, 800, 50, { isStatic: true }), Bodies.rectangle(400, 0, 800, 50, { isStatic: true }),
Bodies.rectangle(400, 600, 800, 50, { isStatic: true }), Bodies.rectangle(400, 600, 800, 50, { isStatic: true }),
@ -39,7 +39,7 @@ Example.rounded = function() {
Bodies.rectangle(0, 300, 50, 600, { isStatic: true }) Bodies.rectangle(0, 300, 50, 600, { isStatic: true })
]); ]);
World.add(world, [ Composite.add(world, [
Bodies.rectangle(200, 200, 100, 100, { Bodies.rectangle(200, 200, 100, 100, {
chamfer: { radius: 20 } chamfer: { radius: 20 }
}), }),
@ -85,7 +85,7 @@ Example.rounded = function() {
} }
}); });
World.add(world, mouseConstraint); Composite.add(world, mouseConstraint);
// keep the mouse in sync with rendering // keep the mouse in sync with rendering
render.mouse = mouse; render.mouse = mouse;

View file

@ -7,7 +7,7 @@ Example.sensors = function() {
Events = Matter.Events, Events = Matter.Events,
MouseConstraint = Matter.MouseConstraint, MouseConstraint = Matter.MouseConstraint,
Mouse = Matter.Mouse, Mouse = Matter.Mouse,
World = Matter.World, Composite = Matter.Composite,
Bodies = Matter.Bodies; Bodies = Matter.Bodies;
// create engine // create engine
@ -45,7 +45,7 @@ Example.sensors = function() {
} }
}); });
World.add(world, [ Composite.add(world, [
collider, collider,
Bodies.rectangle(400, 600, 800, 50, { Bodies.rectangle(400, 600, 800, 50, {
isStatic: true, isStatic: true,
@ -56,7 +56,7 @@ Example.sensors = function() {
}) })
]); ]);
World.add(world, Composite.add(world,
Bodies.circle(400, 40, 30, { Bodies.circle(400, 40, 30, {
render: { render: {
strokeStyle: colorB, strokeStyle: colorB,
@ -106,7 +106,7 @@ Example.sensors = function() {
} }
}); });
World.add(world, mouseConstraint); Composite.add(world, mouseConstraint);
// keep the mouse in sync with rendering // keep the mouse in sync with rendering
render.mouse = mouse; render.mouse = mouse;

View file

@ -9,7 +9,7 @@ Example.sleeping = function() {
Events = Matter.Events, Events = Matter.Events,
MouseConstraint = Matter.MouseConstraint, MouseConstraint = Matter.MouseConstraint,
Mouse = Matter.Mouse, Mouse = Matter.Mouse,
World = Matter.World, Composite = Matter.Composite,
Bodies = Matter.Bodies; Bodies = Matter.Bodies;
// create engine // create engine
@ -36,7 +36,7 @@ Example.sleeping = function() {
Runner.run(runner, engine); Runner.run(runner, engine);
// add bodies // add bodies
World.add(world, [ Composite.add(world, [
// walls // walls
Bodies.rectangle(400, 0, 800, 50, { isStatic: true }), Bodies.rectangle(400, 0, 800, 50, { isStatic: true }),
Bodies.rectangle(400, 600, 800, 50, { isStatic: true }), Bodies.rectangle(400, 600, 800, 50, { isStatic: true }),
@ -59,7 +59,7 @@ Example.sleeping = function() {
} }
}); });
World.add(world, stack); Composite.add(world, stack);
for (var i = 0; i < stack.bodies.length; i++) { for (var i = 0; i < stack.bodies.length; i++) {
Events.on(stack.bodies[i], 'sleepStart sleepEnd', function(event) { Events.on(stack.bodies[i], 'sleepStart sleepEnd', function(event) {
@ -80,7 +80,7 @@ Example.sleeping = function() {
} }
}); });
World.add(world, mouseConstraint); Composite.add(world, mouseConstraint);
// keep the mouse in sync with rendering // keep the mouse in sync with rendering
render.mouse = mouse; render.mouse = mouse;

View file

@ -9,7 +9,7 @@ Example.slingshot = function() {
Constraint = Matter.Constraint, Constraint = Matter.Constraint,
MouseConstraint = Matter.MouseConstraint, MouseConstraint = Matter.MouseConstraint,
Mouse = Matter.Mouse, Mouse = Matter.Mouse,
World = Matter.World, Composite = Matter.Composite,
Bodies = Matter.Bodies; Bodies = Matter.Bodies;
// create engine // create engine
@ -54,12 +54,12 @@ Example.slingshot = function() {
return Bodies.rectangle(x, y, 25, 40); return Bodies.rectangle(x, y, 25, 40);
}); });
World.add(engine.world, [ground, pyramid, ground2, pyramid2, rock, elastic]); Composite.add(engine.world, [ground, pyramid, ground2, pyramid2, rock, elastic]);
Events.on(engine, 'afterUpdate', function() { Events.on(engine, 'afterUpdate', function() {
if (mouseConstraint.mouse.button === -1 && (rock.position.x > 190 || rock.position.y < 430)) { if (mouseConstraint.mouse.button === -1 && (rock.position.x > 190 || rock.position.y < 430)) {
rock = Bodies.polygon(170, 450, 7, 20, rockOptions); rock = Bodies.polygon(170, 450, 7, 20, rockOptions);
World.add(engine.world, rock); Composite.add(engine.world, rock);
elastic.bodyB = rock; elastic.bodyB = rock;
} }
}); });
@ -76,7 +76,7 @@ Example.slingshot = function() {
} }
}); });
World.add(world, mouseConstraint); Composite.add(world, mouseConstraint);
// keep the mouse in sync with rendering // keep the mouse in sync with rendering
render.mouse = mouse; render.mouse = mouse;

View file

@ -7,7 +7,7 @@ Example.softBody = function() {
Composites = Matter.Composites, Composites = Matter.Composites,
MouseConstraint = Matter.MouseConstraint, MouseConstraint = Matter.MouseConstraint,
Mouse = Matter.Mouse, Mouse = Matter.Mouse,
World = Matter.World, Composite = Matter.Composite,
Bodies = Matter.Bodies; Bodies = Matter.Bodies;
// create engine // create engine
@ -38,7 +38,7 @@ Example.softBody = function() {
render: { visible: true } render: { visible: true }
}; };
World.add(world, [ Composite.add(world, [
// see softBody function defined later in this file // see softBody function defined later in this file
Example.softBody.softBody(250, 100, 5, 5, 0, 0, true, 18, particleOptions), Example.softBody.softBody(250, 100, 5, 5, 0, 0, true, 18, particleOptions),
Example.softBody.softBody(400, 300, 8, 3, 0, 0, true, 15, particleOptions), Example.softBody.softBody(400, 300, 8, 3, 0, 0, true, 15, particleOptions),
@ -62,7 +62,7 @@ Example.softBody = function() {
} }
}); });
World.add(world, mouseConstraint); Composite.add(world, mouseConstraint);
// keep the mouse in sync with rendering // keep the mouse in sync with rendering
render.mouse = mouse; render.mouse = mouse;

View file

@ -8,7 +8,7 @@ Example.sprites = function() {
Common = Matter.Common, Common = Matter.Common,
MouseConstraint = Matter.MouseConstraint, MouseConstraint = Matter.MouseConstraint,
Mouse = Matter.Mouse, Mouse = Matter.Mouse,
World = Matter.World, Composite = Matter.Composite,
Bodies = Matter.Bodies; Bodies = Matter.Bodies;
// create engine // create engine
@ -42,7 +42,7 @@ Example.sprites = function() {
world.bodies = []; world.bodies = [];
// these static walls will not be rendered in this sprites example, see options // these static walls will not be rendered in this sprites example, see options
World.add(world, [ Composite.add(world, [
Bodies.rectangle(400, -offset, 800.5 + 2 * offset, 50.5, options), Bodies.rectangle(400, -offset, 800.5 + 2 * offset, 50.5, options),
Bodies.rectangle(400, 600 + offset, 800.5 + 2 * offset, 50.5, options), Bodies.rectangle(400, 600 + offset, 800.5 + 2 * offset, 50.5, options),
Bodies.rectangle(800 + offset, 300, 50.5, 600.5 + 2 * offset, options), Bodies.rectangle(800 + offset, 300, 50.5, 600.5 + 2 * offset, options),
@ -74,7 +74,7 @@ Example.sprites = function() {
} }
}); });
World.add(world, stack); Composite.add(world, stack);
// add mouse control // add mouse control
var mouse = Mouse.create(render.canvas), var mouse = Mouse.create(render.canvas),
@ -88,7 +88,7 @@ Example.sprites = function() {
} }
}); });
World.add(world, mouseConstraint); Composite.add(world, mouseConstraint);
// keep the mouse in sync with rendering // keep the mouse in sync with rendering
render.mouse = mouse; render.mouse = mouse;

View file

@ -7,7 +7,7 @@ Example.stack = function() {
Composites = Matter.Composites, Composites = Matter.Composites,
MouseConstraint = Matter.MouseConstraint, MouseConstraint = Matter.MouseConstraint,
Mouse = Matter.Mouse, Mouse = Matter.Mouse,
World = Matter.World, Composite = Matter.Composite,
Bodies = Matter.Bodies; Bodies = Matter.Bodies;
// create engine // create engine
@ -36,7 +36,7 @@ Example.stack = function() {
return Bodies.rectangle(x, y, 40, 40); return Bodies.rectangle(x, y, 40, 40);
}); });
World.add(world, [ Composite.add(world, [
stack, stack,
// walls // walls
Bodies.rectangle(400, 0, 800, 50, { isStatic: true }), Bodies.rectangle(400, 0, 800, 50, { isStatic: true }),
@ -57,7 +57,7 @@ Example.stack = function() {
} }
}); });
World.add(world, mouseConstraint); Composite.add(world, mouseConstraint);
// keep the mouse in sync with rendering // keep the mouse in sync with rendering
render.mouse = mouse; render.mouse = mouse;

View file

@ -9,7 +9,7 @@ Example.staticFriction = function() {
Events = Matter.Events, Events = Matter.Events,
MouseConstraint = Matter.MouseConstraint, MouseConstraint = Matter.MouseConstraint,
Mouse = Matter.Mouse, Mouse = Matter.Mouse,
World = Matter.World, Composite = Matter.Composite,
Bodies = Matter.Bodies; Bodies = Matter.Bodies;
// create engine // create engine
@ -46,7 +46,7 @@ Example.staticFriction = function() {
}); });
}); });
World.add(world, [ Composite.add(world, [
body, body,
stack, stack,
// walls // walls
@ -82,7 +82,7 @@ Example.staticFriction = function() {
} }
}); });
World.add(world, mouseConstraint); Composite.add(world, mouseConstraint);
// keep the mouse in sync with rendering // keep the mouse in sync with rendering
render.mouse = mouse; render.mouse = mouse;

View file

@ -7,7 +7,7 @@ Example.stress = function() {
Composites = Matter.Composites, Composites = Matter.Composites,
MouseConstraint = Matter.MouseConstraint, MouseConstraint = Matter.MouseConstraint,
Mouse = Matter.Mouse, Mouse = Matter.Mouse,
World = Matter.World, Composite = Matter.Composite,
Bodies = Matter.Bodies; Bodies = Matter.Bodies;
// create engine // create engine
@ -35,7 +35,7 @@ Example.stress = function() {
return Bodies.rectangle(x, y, 35, 35); return Bodies.rectangle(x, y, 35, 35);
}); });
World.add(world, [ Composite.add(world, [
stack, stack,
Bodies.rectangle(400, 0, 800, 50, { isStatic: true }), Bodies.rectangle(400, 0, 800, 50, { isStatic: true }),
Bodies.rectangle(400, 600, 800, 50, { isStatic: true }), Bodies.rectangle(400, 600, 800, 50, { isStatic: true }),
@ -55,7 +55,7 @@ Example.stress = function() {
} }
}); });
World.add(world, mouseConstraint); Composite.add(world, mouseConstraint);
// keep the mouse in sync with rendering // keep the mouse in sync with rendering
render.mouse = mouse; render.mouse = mouse;

View file

@ -7,7 +7,7 @@ Example.stress2 = function() {
Composites = Matter.Composites, Composites = Matter.Composites,
MouseConstraint = Matter.MouseConstraint, MouseConstraint = Matter.MouseConstraint,
Mouse = Matter.Mouse, Mouse = Matter.Mouse,
World = Matter.World, Composite = Matter.Composite,
Bodies = Matter.Bodies; Bodies = Matter.Bodies;
// create engine // create engine
@ -35,7 +35,7 @@ Example.stress2 = function() {
return Bodies.rectangle(x, y, 25, 25); return Bodies.rectangle(x, y, 25, 25);
}); });
World.add(world, [ Composite.add(world, [
stack, stack,
Bodies.rectangle(400, 0, 800, 50, { isStatic: true }), Bodies.rectangle(400, 0, 800, 50, { isStatic: true }),
Bodies.rectangle(400, 600, 800, 50, { isStatic: true }), Bodies.rectangle(400, 600, 800, 50, { isStatic: true }),
@ -55,7 +55,7 @@ Example.stress2 = function() {
} }
}); });
World.add(world, mouseConstraint); Composite.add(world, mouseConstraint);
// keep the mouse in sync with rendering // keep the mouse in sync with rendering
render.mouse = mouse; render.mouse = mouse;

View file

@ -7,7 +7,7 @@ Example.svg = function() {
Common = Matter.Common, Common = Matter.Common,
MouseConstraint = Matter.MouseConstraint, MouseConstraint = Matter.MouseConstraint,
Mouse = Matter.Mouse, Mouse = Matter.Mouse,
World = Matter.World, Composite = Matter.Composite,
Vertices = Matter.Vertices, Vertices = Matter.Vertices,
Svg = Matter.Svg, Svg = Matter.Svg,
Bodies = Matter.Bodies; Bodies = Matter.Bodies;
@ -59,7 +59,7 @@ Example.svg = function() {
var vertexSets = select(root, 'path') var vertexSets = select(root, 'path')
.map(function(path) { return Vertices.scale(Svg.pathToVertices(path, 30), 0.4, 0.4); }); .map(function(path) { return Vertices.scale(Svg.pathToVertices(path, 30), 0.4, 0.4); });
World.add(world, Bodies.fromVertices(100 + i * 150, 200 + i * 50, vertexSets, { Composite.add(world, Bodies.fromVertices(100 + i * 150, 200 + i * 50, vertexSets, {
render: { render: {
fillStyle: color, fillStyle: color,
strokeStyle: color, strokeStyle: color,
@ -75,7 +75,7 @@ Example.svg = function() {
var vertexSets = select(root, 'path') var vertexSets = select(root, 'path')
.map(function(path) { return Svg.pathToVertices(path, 30); }); .map(function(path) { return Svg.pathToVertices(path, 30); });
World.add(world, Bodies.fromVertices(400, 80, vertexSets, { Composite.add(world, Bodies.fromVertices(400, 80, vertexSets, {
render: { render: {
fillStyle: color, fillStyle: color,
strokeStyle: color, strokeStyle: color,
@ -87,7 +87,7 @@ Example.svg = function() {
Common.warn('Fetch is not available. Could not load SVG.'); Common.warn('Fetch is not available. Could not load SVG.');
} }
World.add(world, [ Composite.add(world, [
Bodies.rectangle(400, 0, 800, 50, { isStatic: true }), Bodies.rectangle(400, 0, 800, 50, { isStatic: true }),
Bodies.rectangle(400, 600, 800, 50, { isStatic: true }), Bodies.rectangle(400, 600, 800, 50, { isStatic: true }),
Bodies.rectangle(800, 300, 50, 600, { isStatic: true }), Bodies.rectangle(800, 300, 50, 600, { isStatic: true }),
@ -106,7 +106,7 @@ Example.svg = function() {
} }
}); });
World.add(world, mouseConstraint); Composite.add(world, mouseConstraint);
// keep the mouse in sync with rendering // keep the mouse in sync with rendering
render.mouse = mouse; render.mouse = mouse;

View file

@ -8,7 +8,7 @@ Example.terrain = function() {
Common = Matter.Common, Common = Matter.Common,
MouseConstraint = Matter.MouseConstraint, MouseConstraint = Matter.MouseConstraint,
Mouse = Matter.Mouse, Mouse = Matter.Mouse,
World = Matter.World, Composite = Matter.Composite,
Query = Matter.Query, Query = Matter.Query,
Svg = Matter.Svg, Svg = Matter.Svg,
Bodies = Matter.Bodies; Bodies = Matter.Bodies;
@ -63,7 +63,7 @@ Example.terrain = function() {
} }
}, true); }, true);
World.add(world, terrain); Composite.add(world, terrain);
var bodyOptions = { var bodyOptions = {
frictionAir: 0, frictionAir: 0,
@ -71,7 +71,7 @@ Example.terrain = function() {
restitution: 0.6 restitution: 0.6
}; };
World.add(world, Composites.stack(80, 100, 20, 20, 10, 10, function(x, y) { Composite.add(world, Composites.stack(80, 100, 20, 20, 10, 10, function(x, y) {
if (Query.point([terrain], { x: x, y: y }).length === 0) { if (Query.point([terrain], { x: x, y: y }).length === 0) {
return Bodies.polygon(x, y, 5, 12, bodyOptions); return Bodies.polygon(x, y, 5, 12, bodyOptions);
} }
@ -93,7 +93,7 @@ Example.terrain = function() {
} }
}); });
World.add(world, mouseConstraint); Composite.add(world, mouseConstraint);
// keep the mouse in sync with rendering // keep the mouse in sync with rendering
render.mouse = mouse; render.mouse = mouse;

View file

@ -11,7 +11,6 @@ Example.timescale = function() {
Common = Matter.Common, Common = Matter.Common,
MouseConstraint = Matter.MouseConstraint, MouseConstraint = Matter.MouseConstraint,
Mouse = Matter.Mouse, Mouse = Matter.Mouse,
World = Matter.World,
Bodies = Matter.Bodies; Bodies = Matter.Bodies;
// create engine // create engine
@ -36,7 +35,7 @@ Example.timescale = function() {
Runner.run(runner, engine); Runner.run(runner, engine);
// add bodies // add bodies
World.add(world, [ Composite.add(world, [
Bodies.rectangle(400, 0, 800, 50, { isStatic: true }), Bodies.rectangle(400, 0, 800, 50, { isStatic: true }),
Bodies.rectangle(400, 600, 800, 50, { isStatic: true }), Bodies.rectangle(400, 600, 800, 50, { isStatic: true }),
Bodies.rectangle(800, 300, 50, 600, { isStatic: true }), Bodies.rectangle(800, 300, 50, 600, { isStatic: true }),
@ -95,12 +94,12 @@ Example.timescale = function() {
}; };
// add some small bouncy circles... remember Swordfish? // add some small bouncy circles... remember Swordfish?
World.add(world, Composites.stack(20, 100, 15, 3, 20, 40, function(x, y) { Composite.add(world, Composites.stack(20, 100, 15, 3, 20, 40, function(x, y) {
return Bodies.circle(x, y, Common.random(10, 20), bodyOptions); return Bodies.circle(x, y, Common.random(10, 20), bodyOptions);
})); }));
// add some larger random bouncy objects // add some larger random bouncy objects
World.add(world, Composites.stack(50, 50, 8, 3, 0, 0, function(x, y) { Composite.add(world, Composites.stack(50, 50, 8, 3, 0, 0, function(x, y) {
switch (Math.round(Common.random(0, 1))) { switch (Math.round(Common.random(0, 1))) {
case 0: case 0:
@ -127,7 +126,7 @@ Example.timescale = function() {
} }
}); });
World.add(world, mouseConstraint); Composite.add(world, mouseConstraint);
// keep the mouse in sync with rendering // keep the mouse in sync with rendering
render.mouse = mouse; render.mouse = mouse;

View file

@ -9,7 +9,7 @@ Example.views = function() {
Common = Matter.Common, Common = Matter.Common,
MouseConstraint = Matter.MouseConstraint, MouseConstraint = Matter.MouseConstraint,
Mouse = Matter.Mouse, Mouse = Matter.Mouse,
World = Matter.World, Composite = Matter.Composite,
Vector = Matter.Vector, Vector = Matter.Vector,
Bounds = Matter.Bounds, Bounds = Matter.Bounds,
Bodies = Matter.Bodies; Bodies = Matter.Bodies;
@ -48,7 +48,7 @@ Example.views = function() {
} }
}); });
World.add(world, mouseConstraint); Composite.add(world, mouseConstraint);
// keep the mouse in sync with rendering // keep the mouse in sync with rendering
render.mouse = mouse; render.mouse = mouse;
@ -70,7 +70,7 @@ Example.views = function() {
} }
}); });
World.add(world, [ Composite.add(world, [
stack, stack,
// walls // walls
Bodies.rectangle(400, 0, 800, 50, { isStatic: true }), Bodies.rectangle(400, 0, 800, 50, { isStatic: true }),

View file

@ -7,7 +7,7 @@ Example.wreckingBall = function() {
Composites = Matter.Composites, Composites = Matter.Composites,
MouseConstraint = Matter.MouseConstraint, MouseConstraint = Matter.MouseConstraint,
Mouse = Matter.Mouse, Mouse = Matter.Mouse,
World = Matter.World, Composite = Matter.Composite,
Constraint = Matter.Constraint, Constraint = Matter.Constraint,
Bodies = Matter.Bodies; Bodies = Matter.Bodies;
@ -40,7 +40,7 @@ Example.wreckingBall = function() {
return Bodies.rectangle(x, y, 40, 40); return Bodies.rectangle(x, y, 40, 40);
}); });
World.add(world, [ Composite.add(world, [
stack, stack,
// walls // walls
Bodies.rectangle(400, 0, 800, 50, { isStatic: true }), Bodies.rectangle(400, 0, 800, 50, { isStatic: true }),
@ -51,8 +51,8 @@ Example.wreckingBall = function() {
var ball = Bodies.circle(100, 400, 50, { density: 0.04, frictionAir: 0.005}); var ball = Bodies.circle(100, 400, 50, { density: 0.04, frictionAir: 0.005});
World.add(world, ball); Composite.add(world, ball);
World.add(world, Constraint.create({ Composite.add(world, Constraint.create({
pointA: { x: 300, y: 100 }, pointA: { x: 300, y: 100 },
bodyB: ball bodyB: ball
})); }));
@ -69,7 +69,7 @@ Example.wreckingBall = function() {
} }
}); });
World.add(world, mouseConstraint); Composite.add(world, mouseConstraint);
// keep the mouse in sync with rendering // keep the mouse in sync with rendering
render.mouse = mouse; render.mouse = mouse;