Skip to content

Commit

Permalink
change all examples to use Composite.add instead of the alias World.add
Browse files Browse the repository at this point in the history
  • Loading branch information
liabru committed Apr 6, 2021
1 parent 9ad980b commit a3f298f
Show file tree
Hide file tree
Showing 43 changed files with 159 additions and 169 deletions.
6 changes: 3 additions & 3 deletions examples/airFriction.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Example.airFriction = function() {
Runner = Matter.Runner,
MouseConstraint = Matter.MouseConstraint,
Mouse = Matter.Mouse,
World = Matter.World,

This comment has been minimized.

Copy link
@VarshithGudala

VarshithGudala Jul 21, 2021

good

This comment has been minimized.

Copy link
@NatC02

NatC02 Oct 11, 2021

good

This comment has been minimized.

Copy link
@BobBobbens

BobBobbens Aug 19, 2022

good

Composite = Matter.Composite,
Bodies = Matter.Bodies;

// create engine
Expand All @@ -31,7 +31,7 @@ Example.airFriction = function() {
Runner.run(runner, engine);

// add bodies
World.add(world, [
Composite.add(world, [
// falling blocks
Bodies.rectangle(200, 100, 60, 60, { frictionAir: 0.001 }),
Bodies.rectangle(400, 100, 60, 60, { frictionAir: 0.05 }),
Expand All @@ -56,7 +56,7 @@ Example.airFriction = function() {
}
});

World.add(world, mouseConstraint);
Composite.add(world, mouseConstraint);

// keep the mouse in sync with rendering
render.mouse = mouse;
Expand Down
7 changes: 3 additions & 4 deletions examples/avalanche.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ Example.avalanche = function() {
Common = Matter.Common,
MouseConstraint = Matter.MouseConstraint,
Mouse = Matter.Mouse,
World = Matter.World,
Bodies = Matter.Bodies;

// create engine
Expand Down Expand Up @@ -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 });
});

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(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' } })
Expand All @@ -70,7 +69,7 @@ Example.avalanche = function() {
}
});

World.add(world, mouseConstraint);
Composite.add(world, mouseConstraint);

// keep the mouse in sync with rendering
render.mouse = mouse;
Expand Down
7 changes: 3 additions & 4 deletions examples/ballPool.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ Example.ballPool = function() {
Common = Matter.Common,
MouseConstraint = Matter.MouseConstraint,
Mouse = Matter.Mouse,
World = Matter.World,
Bodies = Matter.Bodies;

// create engine
Expand All @@ -46,15 +45,15 @@ Example.ballPool = function() {
Runner.run(runner, engine);

// add bodies
World.add(world, [
Composite.add(world, [
Bodies.rectangle(400, 600, 1200, 50.5, { isStatic: true, render: { fillStyle: '#060a19' } })
]);

var stack = Composites.stack(100, 0, 10, 8, 10, 10, function(x, y) {
return Bodies.circle(x, y, Common.random(15, 30), { restitution: 0.6, friction: 0.1 });
});

World.add(world, [
Composite.add(world, [
stack,
Bodies.polygon(200, 460, 3, 60),
Bodies.polygon(400, 460, 5, 60),
Expand All @@ -73,7 +72,7 @@ Example.ballPool = function() {
}
});

World.add(world, mouseConstraint);
Composite.add(world, mouseConstraint);

// keep the mouse in sync with rendering
render.mouse = mouse;
Expand Down
6 changes: 3 additions & 3 deletions examples/bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Example.bridge = function() {
Constraint = Matter.Constraint,
MouseConstraint = Matter.MouseConstraint,
Mouse = Matter.Mouse,
World = Matter.World,
Composite = Matter.Composite,
Bodies = Matter.Bodies;

// create engine
Expand Down Expand Up @@ -61,7 +61,7 @@ Example.bridge = function() {
return Bodies.rectangle(x, y, 50, 50, Common.random(20, 40));
});

World.add(world, [
Composite.add(world, [
bridge,
stack,
Bodies.rectangle(30, 490, 220, 380, {
Expand Down Expand Up @@ -100,7 +100,7 @@ Example.bridge = function() {
}
});

World.add(world, mouseConstraint);
Composite.add(world, mouseConstraint);

// keep the mouse in sync with rendering
render.mouse = mouse;
Expand Down
8 changes: 4 additions & 4 deletions examples/broadphase.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Example.broadphase = function() {
Common = Matter.Common,
MouseConstraint = Matter.MouseConstraint,
Mouse = Matter.Mouse,
World = Matter.World,
Composite = Matter.Composite,
Bodies = Matter.Bodies;

// create engine
Expand All @@ -34,7 +34,7 @@ Example.broadphase = function() {
Runner.run(runner, engine);

// add bodies
World.add(world, [
Composite.add(world, [
// walls
Bodies.rectangle(400, 0, 800, 50, { isStatic: true }),
Bodies.rectangle(400, 600, 800, 50, { isStatic: true }),
Expand All @@ -57,7 +57,7 @@ Example.broadphase = function() {
}
});

World.add(world, stack);
Composite.add(world, stack);

// add mouse control
var mouse = Mouse.create(render.canvas),
Expand All @@ -71,7 +71,7 @@ Example.broadphase = function() {
}
});

World.add(world, mouseConstraint);
Composite.add(world, mouseConstraint);

// keep the mouse in sync with rendering
render.mouse = mouse;
Expand Down
12 changes: 6 additions & 6 deletions examples/car.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Example.car = function() {
Composites = Matter.Composites,
MouseConstraint = Matter.MouseConstraint,
Mouse = Matter.Mouse,
World = Matter.World,
Composite = Matter.Composite,
Bodies = Matter.Bodies;

// create engine
Expand All @@ -33,7 +33,7 @@ Example.car = function() {
Runner.run(runner, engine);

// add bodies
World.add(world, [
Composite.add(world, [
// walls
Bodies.rectangle(400, 0, 800, 50, { isStatic: true }),
Bodies.rectangle(400, 600, 800, 50, { isStatic: true }),
Expand All @@ -43,12 +43,12 @@ Example.car = function() {

// see car function defined later in this file
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;
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(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' }})
Expand All @@ -66,7 +66,7 @@ Example.car = function() {
}
});

World.add(world, mouseConstraint);
Composite.add(world, mouseConstraint);

// keep the mouse in sync with rendering
render.mouse = mouse;
Expand Down
6 changes: 3 additions & 3 deletions examples/catapult.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Example.catapult = function() {
Constraint = Matter.Constraint,
MouseConstraint = Matter.MouseConstraint,
Mouse = Matter.Mouse,
World = Matter.World,
Composite = Matter.Composite,
Bodies = Matter.Bodies,
Body = Matter.Body,
Vector = Matter.Vector;
Expand Down Expand Up @@ -45,7 +45,7 @@ Example.catapult = function() {

var catapult = Bodies.rectangle(400, 520, 320, 20, { collisionFilter: { group: group } });

World.add(world, [
Composite.add(world, [
stack,
catapult,
Bodies.rectangle(400, 600, 800, 50.5, { isStatic: true, render: { fillStyle: '#060a19' } }),
Expand All @@ -72,7 +72,7 @@ Example.catapult = function() {
}
});

World.add(world, mouseConstraint);
Composite.add(world, mouseConstraint);

// keep the mouse in sync with rendering
render.mouse = mouse;
Expand Down
5 changes: 2 additions & 3 deletions examples/chains.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ Example.chains = function() {
Constraint = Matter.Constraint,
MouseConstraint = Matter.MouseConstraint,
Mouse = Matter.Mouse,
World = Matter.World,
Bodies = Matter.Bodies;

// create engine
Expand Down Expand Up @@ -79,7 +78,7 @@ Example.chains = function() {
stiffness: 0.5
}));

World.add(world, [
Composite.add(world, [
ropeA,
ropeB,
ropeC,
Expand All @@ -98,7 +97,7 @@ Example.chains = function() {
}
});

World.add(world, mouseConstraint);
Composite.add(world, mouseConstraint);

// keep the mouse in sync with rendering
render.mouse = mouse;
Expand Down
6 changes: 3 additions & 3 deletions examples/circleStack.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Example.circleStack = function() {
Composites = Matter.Composites,
MouseConstraint = Matter.MouseConstraint,
Mouse = Matter.Mouse,
World = Matter.World,
Composite = Matter.Composite,
Bodies = Matter.Bodies;

// create engine
Expand Down Expand Up @@ -36,7 +36,7 @@ Example.circleStack = function() {
return Bodies.circle(x, y, 20);
});

World.add(world, [
Composite.add(world, [
// walls
Bodies.rectangle(400, 0, 800, 50, { isStatic: true }),
Bodies.rectangle(400, 600, 800, 50, { isStatic: true }),
Expand All @@ -57,7 +57,7 @@ Example.circleStack = function() {
}
});

World.add(world, mouseConstraint);
Composite.add(world, mouseConstraint);

// keep the mouse in sync with rendering
render.mouse = mouse;
Expand Down
6 changes: 3 additions & 3 deletions examples/cloth.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Example.cloth = function() {
Composites = Matter.Composites,
MouseConstraint = Matter.MouseConstraint,
Mouse = Matter.Mouse,
World = Matter.World,
Composite = Matter.Composite,
Bodies = Matter.Bodies;

// create engine
Expand Down Expand Up @@ -38,7 +38,7 @@ Example.cloth = function() {
cloth.bodies[i].isStatic = true;
}

World.add(world, [
Composite.add(world, [
cloth,
Bodies.circle(300, 500, 80, { isStatic: true, render: { fillStyle: '#060a19' }}),
Bodies.rectangle(500, 480, 80, 80, { isStatic: true, render: { fillStyle: '#060a19' }}),
Expand All @@ -57,7 +57,7 @@ Example.cloth = function() {
}
});

World.add(world, mouseConstraint);
Composite.add(world, mouseConstraint);

// keep the mouse in sync with rendering
render.mouse = mouse;
Expand Down
13 changes: 6 additions & 7 deletions examples/collisionFiltering.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ Example.collisionFiltering = function() {
Common = Matter.Common,
MouseConstraint = Matter.MouseConstraint,
Mouse = Matter.Mouse,
World = Matter.World,
Bodies = Matter.Bodies;

// create engine
Expand Down Expand Up @@ -44,7 +43,7 @@ Example.collisionFiltering = function() {
colorC = '#f5d259';

// add floor
World.add(world, Bodies.rectangle(400, 600, 900, 50, {
Composite.add(world, Bodies.rectangle(400, 600, 900, 50, {
isStatic: true,
render: {
fillStyle: 'transparent',
Expand All @@ -53,7 +52,7 @@ Example.collisionFiltering = function() {
}));

// 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) {
var category = redCategory,
color = colorA;
Expand All @@ -80,7 +79,7 @@ Example.collisionFiltering = function() {
);

// this body will only collide with the walls and the green bodies
World.add(world,
Composite.add(world,
Bodies.circle(310, 40, 30, {
collisionFilter: {
mask: defaultCategory | greenCategory
Expand All @@ -92,7 +91,7 @@ Example.collisionFiltering = function() {
);

// this body will only collide with the walls and the red bodies
World.add(world,
Composite.add(world,
Bodies.circle(400, 40, 30, {
collisionFilter: {
mask: defaultCategory | redCategory
Expand All @@ -104,7 +103,7 @@ Example.collisionFiltering = function() {
);

// this body will only collide with the walls and the blue bodies
World.add(world,
Composite.add(world,
Bodies.circle(480, 40, 30, {
collisionFilter: {
mask: defaultCategory | blueCategory
Expand All @@ -127,7 +126,7 @@ Example.collisionFiltering = function() {
}
});

World.add(world, mouseConstraint);
Composite.add(world, mouseConstraint);

// keep the mouse in sync with rendering
render.mouse = mouse;
Expand Down
Loading

0 comments on commit a3f298f

Please sign in to comment.