mirror of
https://github.com/wassname/phaser.git
synced 2026-07-13 01:00:12 +08:00
PointProxy added to allow for easy setting of force and velocity. More p2 tests done. World update done.
This commit is contained in:
+2
-3
@@ -447,7 +447,6 @@ Phaser.Game.prototype = {
|
||||
this.tweens = new Phaser.TweenManager(this);
|
||||
this.input = new Phaser.Input(this);
|
||||
this.sound = new Phaser.SoundManager(this);
|
||||
// this.physics = new Phaser.Physics.Arcade(this);
|
||||
this.physics = new Phaser.Physics.World(this);
|
||||
this.particles = new Phaser.Particles(this);
|
||||
this.plugins = new Phaser.PluginManager(this, this);
|
||||
@@ -616,11 +615,11 @@ Phaser.Game.prototype = {
|
||||
this.tweens.update();
|
||||
this.sound.update();
|
||||
this.input.update();
|
||||
this.physics.update();
|
||||
this.state.update();
|
||||
this.world.update();
|
||||
this.physics.update();
|
||||
this.particles.update();
|
||||
this.plugins.update();
|
||||
this.world.update();
|
||||
|
||||
this.world.postUpdate();
|
||||
this.plugins.postUpdate();
|
||||
|
||||
+165
-42
@@ -31,10 +31,16 @@ Phaser.Physics.Body = function (sprite) {
|
||||
*/
|
||||
this.offset = new Phaser.Point();
|
||||
|
||||
// force
|
||||
|
||||
this.shape = null;
|
||||
|
||||
// this.data = new p2.Body({ mass: 0, position:[this.px2p(sprite.x), this.px2p(sprite.y)], angularVelocity: 1 });
|
||||
this.data = new p2.Body({ position:[this.px2p(sprite.x), this.px2p(sprite.y)] });
|
||||
this.data = new p2.Body({ position:[this.px2p(sprite.x), this.px2p(sprite.y)], mass: 1 });
|
||||
|
||||
/**
|
||||
* @property {Phaser.PointProxy} velocity - The velocity of the body. Set velocity.x to a negative value to move to the left, position to the right. velocity.y negative values move up, positive move down.
|
||||
*/
|
||||
this.velocity = new Phaser.Physics.PointProxy(this.data.velocity);
|
||||
|
||||
/**
|
||||
* @property {number} _sx - Internal cache var.
|
||||
@@ -118,6 +124,82 @@ Phaser.Physics.Body.prototype = {
|
||||
// toLocalFrame
|
||||
// toWorldFrame
|
||||
|
||||
/**
|
||||
* If this Body is dynamic then this will zero its velocity on both axis.
|
||||
*
|
||||
* @method Phaser.Physics.Body#setZeroVelocity
|
||||
*/
|
||||
setZeroVelocity: function () {
|
||||
|
||||
this.data.velocity[0] = 0;
|
||||
this.data.velocity[1] = 0;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets the Body damping and angularDamping to zero.
|
||||
*
|
||||
* @method Phaser.Physics.Body#setZeroDamping
|
||||
*/
|
||||
setZeroDamping: function () {
|
||||
|
||||
this.data.damping = 0;
|
||||
this.data.angularDamping = 0;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* If this Body is dynamic then this will move it to the left by setting its x velocity to the given speed.
|
||||
* The speed is represented in pixels per second. So a value of 100 would move 100 pixels in 1 second (1000ms).
|
||||
*
|
||||
* @method Phaser.Physics.Body#moveLeft
|
||||
* @param {number} speed - The speed at which it should move to the left, in pixels per second.
|
||||
*/
|
||||
moveLeft: function (speed) {
|
||||
|
||||
this.data.velocity[0] = this.px2p(-speed);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* If this Body is dynamic then this will move it to the right by setting its x velocity to the given speed.
|
||||
* The speed is represented in pixels per second. So a value of 100 would move 100 pixels in 1 second (1000ms).
|
||||
*
|
||||
* @method Phaser.Physics.Body#moveRight
|
||||
* @param {number} speed - The speed at which it should move to the right, in pixels per second.
|
||||
*/
|
||||
moveRight: function (speed) {
|
||||
|
||||
this.data.velocity[0] = this.px2p(speed);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* If this Body is dynamic then this will move it up by setting its y velocity to the given speed.
|
||||
* The speed is represented in pixels per second. So a value of 100 would move 100 pixels in 1 second (1000ms).
|
||||
*
|
||||
* @method Phaser.Physics.Body#moveUp
|
||||
* @param {number} speed - The speed at which it should move up, in pixels per second.
|
||||
*/
|
||||
moveUp: function (speed) {
|
||||
|
||||
this.data.velocity[1] = this.px2p(-speed);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* If this Body is dynamic then this will move it down by setting its y velocity to the given speed.
|
||||
* The speed is represented in pixels per second. So a value of 100 would move 100 pixels in 1 second (1000ms).
|
||||
*
|
||||
* @method Phaser.Physics.Body#moveDown
|
||||
* @param {number} speed - The speed at which it should move down, in pixels per second.
|
||||
*/
|
||||
moveDown: function (speed) {
|
||||
|
||||
this.data.velocity[1] = this.px2p(speed);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Internal method that updates the Body scale in relation to the parent Sprite.
|
||||
*
|
||||
@@ -401,6 +483,87 @@ Phaser.Physics.Body.prototype = {
|
||||
|
||||
Phaser.Physics.Body.prototype.constructor = Phaser.Physics.Body;
|
||||
|
||||
/**
|
||||
* @name Phaser.Physics.Body#static
|
||||
* @property {boolean} static - Returns true if the Body is static. Setting Body.static to 'false' will make it dynamic.
|
||||
*/
|
||||
Object.defineProperty(Phaser.Physics.Body.prototype, "static", {
|
||||
|
||||
get: function () {
|
||||
|
||||
return (this.data.motionState === Phaser.STATIC);
|
||||
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
|
||||
if (value && this.data.motionState !== Phaser.STATIC)
|
||||
{
|
||||
this.data.motionState = Phaser.STATIC;
|
||||
}
|
||||
else if (!value && this.data.motionState === Phaser.STATIC)
|
||||
{
|
||||
this.data.motionState = Phaser.DYNAMIC;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* @name Phaser.Physics.Body#dynamic
|
||||
* @property {boolean} dynamic - Returns true if the Body is dynamic. Setting Body.dynamic to 'false' will make it static.
|
||||
*/
|
||||
Object.defineProperty(Phaser.Physics.Body.prototype, "dynamic", {
|
||||
|
||||
get: function () {
|
||||
|
||||
return (this.data.motionState === Phaser.DYNAMIC);
|
||||
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
|
||||
if (value && this.data.motionState !== Phaser.DYNAMIC)
|
||||
{
|
||||
this.data.motionState = Phaser.DYNAMIC;
|
||||
}
|
||||
else if (!value && this.data.motionState === Phaser.DYNAMIC)
|
||||
{
|
||||
this.data.motionState = Phaser.STATIC;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* @name Phaser.Physics.Body#kinematic
|
||||
* @property {boolean} kinematic - Returns true if the Body is kinematic. Setting Body.kinematic to 'false' will make it static.
|
||||
*/
|
||||
Object.defineProperty(Phaser.Physics.Body.prototype, "kinematic", {
|
||||
|
||||
get: function () {
|
||||
|
||||
return (this.data.motionState === Phaser.KINEMATIC);
|
||||
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
|
||||
if (value && this.data.motionState !== Phaser.KINEMATIC)
|
||||
{
|
||||
this.data.motionState = Phaser.KINEMATIC;
|
||||
}
|
||||
else if (!value && this.data.motionState === Phaser.KINEMATIC)
|
||||
{
|
||||
this.data.motionState = Phaser.STATIC;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* @name Phaser.Physics.Body#allowSleep
|
||||
* @property {boolean} allowSleep -
|
||||
@@ -554,8 +717,6 @@ Object.defineProperty(Phaser.Physics.Body.prototype, "fixedRotation", {
|
||||
|
||||
});
|
||||
|
||||
// force
|
||||
|
||||
/**
|
||||
* @name Phaser.Physics.Body#inertia
|
||||
* @property {number} inertia - The inertia of the body around the Z axis..
|
||||
@@ -667,8 +828,6 @@ Object.defineProperty(Phaser.Physics.Body.prototype, "sleepSpeedLimit", {
|
||||
|
||||
});
|
||||
|
||||
// velocity
|
||||
|
||||
/**
|
||||
* @name Phaser.Physics.Body#x
|
||||
* @property {number} x - The x coordinate of this Body.
|
||||
@@ -708,39 +867,3 @@ Object.defineProperty(Phaser.Physics.Body.prototype, "y", {
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Object.defineProperties(Phaser.Physics.Body.prototype, {
|
||||
|
||||
"bob": {
|
||||
|
||||
get: function () {
|
||||
|
||||
return { x: 1, y: 2 };
|
||||
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
|
||||
console.log(arguments);
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
"ben": {
|
||||
|
||||
get: function () {
|
||||
|
||||
return { x: 4, y: 5 };
|
||||
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
|
||||
console.log(arguments);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2014 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* A PointProxy is an internal class that allows for direct getter/setter style property access to Arrays and TypedArrays.
|
||||
*
|
||||
* @class Phaser.Physics.PointProxy
|
||||
* @classdesc PointProxy
|
||||
* @constructor
|
||||
* @param {any} destination - The object to bind to.
|
||||
*/
|
||||
Phaser.Physics.PointProxy = function (destination) {
|
||||
|
||||
this.destination = destination;
|
||||
|
||||
};
|
||||
|
||||
Phaser.Physics.PointProxy.prototype.constructor = Phaser.Physics.PointProxy;
|
||||
|
||||
/**
|
||||
* @name Phaser.Physics.PointProxy#x
|
||||
* @property {number} x - The x property of this PointProxy.
|
||||
*/
|
||||
Object.defineProperty(Phaser.Physics.PointProxy.prototype, "x", {
|
||||
|
||||
get: function () {
|
||||
|
||||
return this.destination[0];
|
||||
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
|
||||
this.destination[0] = value;
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* @name Phaser.Physics.PointProxy#y
|
||||
* @property {number} y - The y property of this PointProxy.
|
||||
*/
|
||||
Object.defineProperty(Phaser.Physics.PointProxy.prototype, "y", {
|
||||
|
||||
get: function () {
|
||||
|
||||
return this.destination[1];
|
||||
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
|
||||
this.destination[1] = value;
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
@@ -22,7 +22,7 @@ Phaser.Physics.World = function (game) {
|
||||
*/
|
||||
this.game = game;
|
||||
|
||||
p2.World.call(this);
|
||||
p2.World.call(this, { gravity: [0, 0] });
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user