mirror of
https://github.com/photonstorm/phaser
synced 2024-11-22 20:53:39 +00:00
World.createRotationalSpring will now let you create rotational springs.
This commit is contained in:
parent
6acc8bf9f2
commit
aeb82dbee9
5 changed files with 88 additions and 21 deletions
|
@ -69,7 +69,7 @@ Version 2.1.0 - "Cairhien" - -in development-
|
|||
|
||||
### Updates
|
||||
|
||||
* Updated to the latest build of [p2.js](https://github.com/schteppe/p2.js/commit/d1c7a340c42e4d5d1d939fba5fd13c5e49d6abd2)
|
||||
* Updated to [p2.js 0.6.0](https://github.com/schteppe/p2.js/commit/d1c7a340c42e4d5d1d939fba5fd13c5e49d6abd2) - this was an API breaking change, so please see the p2.js section of this change log specifically if you're using p2 in your game.
|
||||
* TypeScript definition updates to help fix for the `noimplicitany` option (thanks @Waog #1088)
|
||||
* All of the Pixi geom classes have been removed from the build file as they aren't needed (the Phaser.Geom classes overwrite them), saving some space in the process.
|
||||
|
||||
|
@ -91,12 +91,14 @@ Version 2.1.0 - "Cairhien" - -in development-
|
|||
* Group.swap() updates the Z index values properly (thanks @Blank101 #1090)
|
||||
* Device now recognises ChromeOS as a desktop (thanks @alvinsight @hilts-vaughan #1091)
|
||||
|
||||
### p2.js 0.6.0 Changes
|
||||
### p2.js 0.6.0 Changes and New Features
|
||||
|
||||
* DistanceConstraint signature changed to take the new localAnchors.
|
||||
* RevoluteConstraint signature changed to include worldPivot
|
||||
* P2.Body now uses the new Body.type value instead of Body.motionState, however as P2.Body already have a property called `type` we have left the `motionState` getter/setter in for now.
|
||||
* World.enableBodySleeping has been removed and replaced with World.sleepMode.
|
||||
* Phaser P2.Springs are now LinearSprings by default.
|
||||
* World.createRotationalSpring will now let you create rotational springs.
|
||||
|
||||
#### Breaking changes
|
||||
|
||||
|
|
|
@ -24,18 +24,6 @@
|
|||
echo " <script src=\"$path/src/physics/p2/p2.js\"></script>";
|
||||
}
|
||||
|
||||
// Testing a build without these - pretty sure we're safe to ignore them (as we over-write them)
|
||||
// <script src="$path/src/pixi/core/Point.js"></script>
|
||||
// <script src="$path/src/pixi/core/Rectangle.js"></script>
|
||||
// <script src="$path/src/pixi/core/Polygon.js"></script>
|
||||
// <script src="$path/src/pixi/core/Circle.js"></script>
|
||||
// <script src="$path/src/pixi/core/Ellipse.js"></script>
|
||||
// "src/pixi/core/Point.js",
|
||||
// "src/pixi/core/Rectangle.js",
|
||||
// "src/pixi/core/Polygon.js",
|
||||
// "src/pixi/core/Circle.js",
|
||||
// "src/pixi/core/Ellipse.js",
|
||||
|
||||
echo <<<EOL
|
||||
|
||||
<script src="$path/src/pixi/Pixi.js"></script>
|
||||
|
@ -201,6 +189,7 @@ EOL;
|
|||
<script src="$path/src/physics/p2/Body.js"></script>
|
||||
<script src="$path/src/physics/p2/BodyDebug.js"></script>
|
||||
<script src="$path/src/physics/p2/Spring.js"></script>
|
||||
<script src="$path/src/physics/p2/RotationalSpring.js"></script>
|
||||
<script src="$path/src/physics/p2/Material.js"></script>
|
||||
<script src="$path/src/physics/p2/ContactMaterial.js"></script>
|
||||
<script src="$path/src/physics/p2/CollisionGroup.js"></script>
|
||||
|
|
52
src/physics/p2/RotationalSpring.js
Normal file
52
src/physics/p2/RotationalSpring.js
Normal file
|
@ -0,0 +1,52 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2014 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Creates a rotational spring, connecting two bodies. A spring can have a resting length, a stiffness and damping.
|
||||
*
|
||||
* @class Phaser.Physics.P2.RotationalSpring
|
||||
* @classdesc Physics Spring Constructor
|
||||
* @constructor
|
||||
* @param {Phaser.Physics.P2} world - A reference to the P2 World.
|
||||
* @param {p2.Body} bodyA - First connected body.
|
||||
* @param {p2.Body} bodyB - Second connected body.
|
||||
* @param {number} [restAngle] - The relative angle of bodies at which the spring is at rest. If not given, it's set to the current relative angle between the bodies.
|
||||
* @param {number} [stiffness=100] - Stiffness of the spring. A number >= 0.
|
||||
* @param {number} [damping=1] - Damping of the spring. A number >= 0.
|
||||
*/
|
||||
Phaser.Physics.P2.RotationalSpring = function (world, bodyA, bodyB, restAngle, stiffness, damping) {
|
||||
|
||||
/**
|
||||
* @property {Phaser.Game} game - Local reference to game.
|
||||
*/
|
||||
this.game = world.game;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Physics.P2} world - Local reference to P2 World.
|
||||
*/
|
||||
this.world = world;
|
||||
|
||||
if (typeof restAngle === 'undefined') { restAngle = null; }
|
||||
if (typeof stiffness === 'undefined') { stiffness = 100; }
|
||||
if (typeof damping === 'undefined') { damping = 1; }
|
||||
|
||||
if (restAngle)
|
||||
{
|
||||
restAngle = world.pxm(restAngle);
|
||||
}
|
||||
|
||||
var options = {
|
||||
restAngle: restAngle,
|
||||
stiffness: stiffness,
|
||||
damping: damping
|
||||
};
|
||||
|
||||
p2.RotationalSpring.call(this, bodyA, bodyB, options);
|
||||
|
||||
};
|
||||
|
||||
Phaser.Physics.P2.Spring.prototype = Object.create(p2.RotationalSpring.prototype);
|
||||
Phaser.Physics.P2.Spring.prototype.constructor = Phaser.Physics.P2.Spring;
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* Creates a spring, connecting two bodies. A spring can have a resting length, a stiffness and damping.
|
||||
* Creates a linear spring, connecting two bodies. A spring can have a resting length, a stiffness and damping.
|
||||
*
|
||||
* @class Phaser.Physics.P2.Spring
|
||||
* @classdesc Physics Spring Constructor
|
||||
|
@ -65,9 +65,9 @@ Phaser.Physics.P2.Spring = function (world, bodyA, bodyB, restLength, stiffness,
|
|||
options.localAnchorB = [ world.pxm(localB[0]), world.pxm(localB[1]) ];
|
||||
}
|
||||
|
||||
p2.Spring.call(this, bodyA, bodyB, options);
|
||||
p2.LinearSpring.call(this, bodyA, bodyB, options);
|
||||
|
||||
};
|
||||
|
||||
Phaser.Physics.P2.Spring.prototype = Object.create(p2.Spring.prototype);
|
||||
Phaser.Physics.P2.Spring.prototype = Object.create(p2.LinearSpring.prototype);
|
||||
Phaser.Physics.P2.Spring.prototype.constructor = Phaser.Physics.P2.Spring;
|
||||
|
|
|
@ -1295,7 +1295,7 @@ Phaser.Physics.P2.prototype = {
|
|||
},
|
||||
|
||||
/**
|
||||
* Creates a spring, connecting two bodies. A spring can have a resting length, a stiffness and damping.
|
||||
* Creates a linear spring, connecting two bodies. A spring can have a resting length, a stiffness and damping.
|
||||
*
|
||||
* @method Phaser.Physics.P2#createSpring
|
||||
* @param {Phaser.Sprite|Phaser.Physics.P2.Body|p2.Body} bodyA - First connected body.
|
||||
|
@ -1303,9 +1303,6 @@ Phaser.Physics.P2.prototype = {
|
|||
* @param {number} [restLength=1] - Rest length of the spring. A number > 0.
|
||||
* @param {number} [stiffness=100] - Stiffness of the spring. A number >= 0.
|
||||
* @param {number} [damping=1] - Damping of the spring. A number >= 0.
|
||||
* @param {number} [restLength=1] - Rest length of the spring. A number > 0.
|
||||
* @param {number} [stiffness=100] - Stiffness of the spring. A number >= 0.
|
||||
* @param {number} [damping=1] - Damping of the spring. A number >= 0.
|
||||
* @param {Array} [worldA] - Where to hook the spring to body A in world coordinates. This value is an array by 2 elements, x and y, i.e: [32, 32].
|
||||
* @param {Array} [worldB] - Where to hook the spring to body B in world coordinates. This value is an array by 2 elements, x and y, i.e: [32, 32].
|
||||
* @param {Array} [localA] - Where to hook the spring to body A in local body coordinates. This value is an array by 2 elements, x and y, i.e: [32, 32].
|
||||
|
@ -1328,6 +1325,33 @@ Phaser.Physics.P2.prototype = {
|
|||
|
||||
},
|
||||
|
||||
/**
|
||||
* Creates a rotational spring, connecting two bodies. A spring can have a resting length, a stiffness and damping.
|
||||
*
|
||||
* @method Phaser.Physics.P2#createRotationalSpring
|
||||
* @param {Phaser.Sprite|Phaser.Physics.P2.Body|p2.Body} bodyA - First connected body.
|
||||
* @param {Phaser.Sprite|Phaser.Physics.P2.Body|p2.Body} bodyB - Second connected body.
|
||||
* @param {number} [restAngle] - The relative angle of bodies at which the spring is at rest. If not given, it's set to the current relative angle between the bodies.
|
||||
* @param {number} [stiffness=100] - Stiffness of the spring. A number >= 0.
|
||||
* @param {number} [damping=1] - Damping of the spring. A number >= 0.
|
||||
* @return {Phaser.Physics.P2.RotationalSpring} The spring
|
||||
*/
|
||||
createRotationalSpring: function (bodyA, bodyB, restAngle, stiffness, damping) {
|
||||
|
||||
bodyA = this.getBody(bodyA);
|
||||
bodyB = this.getBody(bodyB);
|
||||
|
||||
if (!bodyA || !bodyB)
|
||||
{
|
||||
console.warn('Cannot create Rotational Spring, invalid body objects given');
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.addSpring(new Phaser.Physics.P2.RotationalSpring(this, bodyA, bodyB, restAngle, stiffness, damping));
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Creates a new Body and adds it to the World.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue