0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2024-12-26 13:49:01 -05:00

improved Example.catapult using pin constraint

This commit is contained in:
liabru 2017-05-03 21:28:39 +01:00
parent 130e6b3f56
commit 0e15099479

View file

@ -9,7 +9,9 @@ Example.catapult = function() {
MouseConstraint = Matter.MouseConstraint,
Mouse = Matter.Mouse,
World = Matter.World,
Bodies = Matter.Bodies;
Bodies = Matter.Bodies,
Body = Matter.Body,
Vector = Matter.Vector;
// create engine
var engine = Engine.create(),
@ -35,20 +37,27 @@ Example.catapult = function() {
Runner.run(runner, engine);
// add bodies
var group = Body.nextGroup(true);
var stack = Composites.stack(250, 255, 1, 6, 0, 0, function(x, y) {
return Bodies.rectangle(x, y, 30, 30);
});
var catapult = Bodies.rectangle(400, 520, 320, 20);
var catapult = Bodies.rectangle(400, 520, 320, 20, { collisionFilter: { group: group } });
World.add(world, [
stack,
catapult,
Bodies.rectangle(400, 600, 800, 50.5, { isStatic: true }),
Bodies.rectangle(250, 555, 20, 50, { isStatic: true }),
Bodies.rectangle(400, 535, 20, 80, { isStatic: true, collisionFilter: { group: group } }),
Bodies.circle(560, 100, 50, { density: 0.005 }),
Constraint.create({ bodyA: catapult, pointB: { x: 390, y: 580 } }),
Constraint.create({ bodyA: catapult, pointB: { x: 410, y: 580 } })
Constraint.create({
bodyA: catapult,
pointB: Vector.clone(catapult.position),
stiffness: 1,
length: 0
})
]);
// add mouse control