|
| 1 | +/** |
| 2 | +* @author Richard Davey <rich@photonstorm.com> |
| 3 | +* @copyright 2014 Photon Storm Ltd. |
| 4 | +* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} |
| 5 | +*/ |
| 6 | + |
| 7 | +/** |
| 8 | +* Creates a spring, connecting two bodies. |
| 9 | +* |
| 10 | +* @class Phaser.Physics.Spring |
| 11 | +* @classdesc Physics Spring Constructor |
| 12 | +* @constructor |
| 13 | +* @param {Phaser.Game} game - A reference to the current game. |
| 14 | +* @param {p2.Body} bodyA - First connected body. |
| 15 | +* @param {p2.Body} bodyB - Second connected body. |
| 16 | +* @param {number} [restLength=1] - Rest length of the spring. A number > 0. |
| 17 | +* @param {number} [stiffness=100] - Stiffness of the spring. A number >= 0. |
| 18 | +* @param {number} [damping=1] - Damping of the spring. A number >= 0. |
| 19 | +* @param {Array} [worldA] - Where to hook the spring to body A, in world coordinates, i.e. [32, 32]. |
| 20 | +* @param {Array} [worldB] - Where to hook the spring to body B, in world coordinates, i.e. [32, 32]. |
| 21 | +* @param {Array} [localA] - Where to hook the spring to body A, in local body coordinates. |
| 22 | +* @param {Array} [localB] - Where to hook the spring to body B, in local body coordinates. |
| 23 | +*/ |
| 24 | +Phaser.Physics.Spring = function (game, bodyA, bodyB, restLength, stiffness, damping, worldA, worldB, localA, localB) { |
| 25 | + |
| 26 | + /** |
| 27 | + * @property {Phaser.Game} game - Local reference to game. |
| 28 | + */ |
| 29 | + this.game = game; |
| 30 | + |
| 31 | + if (typeof restLength === 'undefined') { restLength = 1; } |
| 32 | + if (typeof stiffness === 'undefined') { stiffness = 100; } |
| 33 | + if (typeof damping === 'undefined') { damping = 1; } |
| 34 | + |
| 35 | + var options = { |
| 36 | + restLength: restLength, |
| 37 | + stiffness: stiffness, |
| 38 | + damping: damping |
| 39 | + }; |
| 40 | + |
| 41 | + if (typeof worldA !== 'undefined') |
| 42 | + { |
| 43 | + options.worldAnchorA = [ game.math.px2p(worldA[0]), game.math.px2p(worldA[1]) ]; |
| 44 | + } |
| 45 | + |
| 46 | + if (typeof worldB !== 'undefined') |
| 47 | + { |
| 48 | + options.worldAnchorB = [ game.math.px2p(worldB[0]), game.math.px2p(worldB[1]) ]; |
| 49 | + } |
| 50 | + |
| 51 | + if (typeof localA !== 'undefined') |
| 52 | + { |
| 53 | + options.localAnchorA = [ game.math.px2p(localA[0]), game.math.px2p(localA[1]) ]; |
| 54 | + } |
| 55 | + |
| 56 | + if (typeof localB !== 'undefined') |
| 57 | + { |
| 58 | + options.localAnchorB = [ game.math.px2p(localB[0]), game.math.px2p(localB[1]) ]; |
| 59 | + } |
| 60 | + |
| 61 | + p2.Spring.call(this, bodyA, bodyB, options); |
| 62 | + |
| 63 | +} |
| 64 | + |
| 65 | +Phaser.Physics.Spring.prototype = Object.create(p2.Spring.prototype); |
| 66 | +Phaser.Physics.Spring.prototype.constructor = Phaser.Physics.Spring; |
0 commit comments