|
1 | 1 | var Bodies = require('./lib/factory/Bodies'); |
2 | 2 | var Class = require('../../utils/Class'); |
3 | 3 | var Composites = require('./lib/factory/Composites'); |
| 4 | +var Constraint = require('./lib/constraint/Constraint'); |
4 | 5 | var MatterImage = require('./MatterImage'); |
5 | 6 | var MatterSprite = require('./MatterSprite'); |
6 | 7 |
|
@@ -79,6 +80,34 @@ var Factory = new Class({ |
79 | 80 | return stack; |
80 | 81 | }, |
81 | 82 |
|
| 83 | + // To help those used to Box2D |
| 84 | + joint: function (bodyA, bodyB, length, stiffness, options) |
| 85 | + { |
| 86 | + return this.constraint(bodyA, bodyB, length, stiffness, options); |
| 87 | + }, |
| 88 | + |
| 89 | + spring: function (bodyA, bodyB, length, stiffness, options) |
| 90 | + { |
| 91 | + return this.constraint(bodyA, bodyB, length, stiffness, options); |
| 92 | + }, |
| 93 | + |
| 94 | + constraint: function (bodyA, bodyB, length, stiffness, options) |
| 95 | + { |
| 96 | + if (stiffness === undefined) { stiffness = 1; } |
| 97 | + if (options === undefined) { options = {}; } |
| 98 | + |
| 99 | + options.bodyA = (bodyA.type === 'body') ? bodyA : bodyA.body; |
| 100 | + options.bodyB = (bodyB.type === 'body') ? bodyB : bodyB.body; |
| 101 | + options.length = length; |
| 102 | + options.stiffness = stiffness; |
| 103 | + |
| 104 | + var constraint = Constraint.create(options); |
| 105 | + |
| 106 | + this.world.add(constraint); |
| 107 | + |
| 108 | + return constraint; |
| 109 | + }, |
| 110 | + |
82 | 111 | image: function (x, y, key, frame, options) |
83 | 112 | { |
84 | 113 | var image = new MatterImage(this.world, x, y, key, frame, options); |
|
0 commit comments