mirror of
https://github.com/liabru/matter-js.git
synced 2024-12-30 14:29:04 -05:00
deprecated Composites.car and added to car example
This commit is contained in:
parent
313c1503c8
commit
cd9c5d43db
2 changed files with 80 additions and 3 deletions
|
@ -41,11 +41,12 @@ Example.car = function() {
|
||||||
Bodies.rectangle(0, 300, 50, 600, { isStatic: true })
|
Bodies.rectangle(0, 300, 50, 600, { isStatic: true })
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
// see car function defined later in this file
|
||||||
var scale = 0.9;
|
var scale = 0.9;
|
||||||
World.add(world, Composites.car(150, 100, 150 * scale, 30 * scale, 30 * scale));
|
World.add(world, Example.car.car(150, 100, 150 * scale, 30 * scale, 30 * scale));
|
||||||
|
|
||||||
scale = 0.8;
|
scale = 0.8;
|
||||||
World.add(world, Composites.car(350, 300, 150 * scale, 30 * scale, 30 * scale));
|
World.add(world, Example.car.car(350, 300, 150 * scale, 30 * scale, 30 * scale));
|
||||||
|
|
||||||
World.add(world, [
|
World.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' }}),
|
||||||
|
@ -92,6 +93,78 @@ Example.car = function() {
|
||||||
Example.car.title = 'Car';
|
Example.car.title = 'Car';
|
||||||
Example.car.for = '>=0.14.2';
|
Example.car.for = '>=0.14.2';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a composite with simple car setup of bodies and constraints.
|
||||||
|
* @method car
|
||||||
|
* @param {number} xx
|
||||||
|
* @param {number} yy
|
||||||
|
* @param {number} width
|
||||||
|
* @param {number} height
|
||||||
|
* @param {number} wheelSize
|
||||||
|
* @return {composite} A new composite car body
|
||||||
|
*/
|
||||||
|
Example.car.car = function(xx, yy, width, height, wheelSize) {
|
||||||
|
var Body = Matter.Body,
|
||||||
|
Bodies = Matter.Bodies,
|
||||||
|
Composite = Matter.Composite,
|
||||||
|
Constraint = Matter.Constraint;
|
||||||
|
|
||||||
|
var group = Body.nextGroup(true),
|
||||||
|
wheelBase = 20,
|
||||||
|
wheelAOffset = -width * 0.5 + wheelBase,
|
||||||
|
wheelBOffset = width * 0.5 - wheelBase,
|
||||||
|
wheelYOffset = 0;
|
||||||
|
|
||||||
|
var car = Composite.create({ label: 'Car' }),
|
||||||
|
body = Bodies.rectangle(xx, yy, width, height, {
|
||||||
|
collisionFilter: {
|
||||||
|
group: group
|
||||||
|
},
|
||||||
|
chamfer: {
|
||||||
|
radius: height * 0.5
|
||||||
|
},
|
||||||
|
density: 0.0002
|
||||||
|
});
|
||||||
|
|
||||||
|
var wheelA = Bodies.circle(xx + wheelAOffset, yy + wheelYOffset, wheelSize, {
|
||||||
|
collisionFilter: {
|
||||||
|
group: group
|
||||||
|
},
|
||||||
|
friction: 0.8
|
||||||
|
});
|
||||||
|
|
||||||
|
var wheelB = Bodies.circle(xx + wheelBOffset, yy + wheelYOffset, wheelSize, {
|
||||||
|
collisionFilter: {
|
||||||
|
group: group
|
||||||
|
},
|
||||||
|
friction: 0.8
|
||||||
|
});
|
||||||
|
|
||||||
|
var axelA = Constraint.create({
|
||||||
|
bodyB: body,
|
||||||
|
pointB: { x: wheelAOffset, y: wheelYOffset },
|
||||||
|
bodyA: wheelA,
|
||||||
|
stiffness: 1,
|
||||||
|
length: 0
|
||||||
|
});
|
||||||
|
|
||||||
|
var axelB = Constraint.create({
|
||||||
|
bodyB: body,
|
||||||
|
pointB: { x: wheelBOffset, y: wheelYOffset },
|
||||||
|
bodyA: wheelB,
|
||||||
|
stiffness: 1,
|
||||||
|
length: 0
|
||||||
|
});
|
||||||
|
|
||||||
|
Composite.addBody(car, body);
|
||||||
|
Composite.addBody(car, wheelA);
|
||||||
|
Composite.addBody(car, wheelB);
|
||||||
|
Composite.addConstraint(car, axelA);
|
||||||
|
Composite.addConstraint(car, axelB);
|
||||||
|
|
||||||
|
return car;
|
||||||
|
};
|
||||||
|
|
||||||
if (typeof module !== 'undefined') {
|
if (typeof module !== 'undefined') {
|
||||||
module.exports = Example.car;
|
module.exports = Example.car;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ var Constraint = require('../constraint/Constraint');
|
||||||
var Common = require('../core/Common');
|
var Common = require('../core/Common');
|
||||||
var Body = require('../body/Body');
|
var Body = require('../body/Body');
|
||||||
var Bodies = require('./Bodies');
|
var Bodies = require('./Bodies');
|
||||||
|
var deprecated = Common.deprecated;
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
|
@ -229,6 +230,7 @@ var Bodies = require('./Bodies');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a composite with simple car setup of bodies and constraints.
|
* Creates a composite with simple car setup of bodies and constraints.
|
||||||
|
* @deprecated moved to car example
|
||||||
* @method car
|
* @method car
|
||||||
* @param {number} xx
|
* @param {number} xx
|
||||||
* @param {number} yy
|
* @param {number} yy
|
||||||
|
@ -294,6 +296,8 @@ var Bodies = require('./Bodies');
|
||||||
return car;
|
return car;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
deprecated(Composites, 'car', 'Composites.car ➤ moved to car example');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a simple soft body like object.
|
* Creates a simple soft body like object.
|
||||||
* @method softBody
|
* @method softBody
|
||||||
|
|
Loading…
Reference in a new issue