mirror of
https://github.com/wassname/phaser.git
synced 2026-08-01 12:50:06 +08:00
The entire Phaser library has been updated to match the new JSHint configuration.
This commit is contained in:
@@ -27,10 +27,10 @@ function QuadTree(bounds, pointQuad, maxDepth, maxChildren){
|
||||
}
|
||||
|
||||
/**
|
||||
* The root node of the QuadTree which covers the entire area being segmented.
|
||||
* @property root
|
||||
* @type Node
|
||||
*/
|
||||
* The root node of the QuadTree which covers the entire area being segmented.
|
||||
* @property root
|
||||
* @type Node
|
||||
*/
|
||||
this.root = node;
|
||||
}
|
||||
|
||||
@@ -299,7 +299,7 @@ BoundsNode.prototype.insert = function(item){
|
||||
console.log("radius:",item.boundingRadius);
|
||||
console.log("item x:",item.position[0] - item.boundingRadius,"x range:",node.bounds.x,node.bounds.x+node.bounds.width);
|
||||
console.log("item y:",item.position[1] - item.boundingRadius,"y range:",node.bounds.y,node.bounds.y+node.bounds.height);
|
||||
*/
|
||||
*/
|
||||
|
||||
//todo: make _bounds bounds
|
||||
if( !(item instanceof Plane) && // Plane is infinite.. Make it a "stuck" child
|
||||
|
||||
@@ -19,24 +19,24 @@ function SAP1DBroadphase(world){
|
||||
Broadphase.apply(this);
|
||||
|
||||
/**
|
||||
* List of bodies currently in the broadphase.
|
||||
* @property axisList
|
||||
* @type {Array}
|
||||
*/
|
||||
* List of bodies currently in the broadphase.
|
||||
* @property axisList
|
||||
* @type {Array}
|
||||
*/
|
||||
this.axisList = world.bodies.slice(0);
|
||||
|
||||
/**
|
||||
* The world to search in.
|
||||
* @property world
|
||||
* @type {World}
|
||||
*/
|
||||
* The world to search in.
|
||||
* @property world
|
||||
* @type {World}
|
||||
*/
|
||||
this.world = world;
|
||||
|
||||
/**
|
||||
* Axis to sort the bodies along. Set to 0 for x axis, and 1 for y axis. For best performance, choose an axis that the bodies are spread out more on.
|
||||
* @property axisIndex
|
||||
* @type {Number}
|
||||
*/
|
||||
* Axis to sort the bodies along. Set to 0 for x axis, and 1 for y axis. For best performance, choose an axis that the bodies are spread out more on.
|
||||
* @property axisIndex
|
||||
* @type {Number}
|
||||
*/
|
||||
this.axisIndex = 0;
|
||||
|
||||
// Add listeners to update the list of bodies.
|
||||
|
||||
@@ -12,24 +12,24 @@ module.exports = Constraint;
|
||||
function Constraint(bodyA,bodyB){
|
||||
|
||||
/**
|
||||
* Equations to be solved in this constraint
|
||||
* @property equations
|
||||
* @type {Array}
|
||||
*/
|
||||
* Equations to be solved in this constraint
|
||||
* @property equations
|
||||
* @type {Array}
|
||||
*/
|
||||
this.equations = [];
|
||||
|
||||
/**
|
||||
* First body participating in the constraint.
|
||||
* @property bodyA
|
||||
* @type {Body}
|
||||
*/
|
||||
* First body participating in the constraint.
|
||||
* @property bodyA
|
||||
* @type {Body}
|
||||
*/
|
||||
this.bodyA = bodyA;
|
||||
|
||||
/**
|
||||
* Second body participating in the constraint.
|
||||
* @property bodyB
|
||||
* @type {Body}
|
||||
*/
|
||||
* Second body participating in the constraint.
|
||||
* @property bodyB
|
||||
* @type {Body}
|
||||
*/
|
||||
this.bodyB = bodyB;
|
||||
};
|
||||
|
||||
|
||||
@@ -12,45 +12,45 @@ module.exports = Equation;
|
||||
function Equation(bi,bj,minForce,maxForce){
|
||||
|
||||
/**
|
||||
* Minimum force to apply when solving
|
||||
* @property minForce
|
||||
* @type {Number}
|
||||
*/
|
||||
* Minimum force to apply when solving
|
||||
* @property minForce
|
||||
* @type {Number}
|
||||
*/
|
||||
this.minForce = typeof(minForce)=="undefined" ? -1e6 : minForce;
|
||||
|
||||
/**
|
||||
* Max force to apply when solving
|
||||
* @property maxForce
|
||||
* @type {Number}
|
||||
*/
|
||||
* Max force to apply when solving
|
||||
* @property maxForce
|
||||
* @type {Number}
|
||||
*/
|
||||
this.maxForce = typeof(maxForce)=="undefined" ? 1e6 : maxForce;
|
||||
|
||||
/**
|
||||
* First body participating in the constraint
|
||||
* @property bi
|
||||
* @type {Body}
|
||||
*/
|
||||
* First body participating in the constraint
|
||||
* @property bi
|
||||
* @type {Body}
|
||||
*/
|
||||
this.bi = bi;
|
||||
|
||||
/**
|
||||
* Second body participating in the constraint
|
||||
* @property bj
|
||||
* @type {Body}
|
||||
*/
|
||||
* Second body participating in the constraint
|
||||
* @property bj
|
||||
* @type {Body}
|
||||
*/
|
||||
this.bj = bj;
|
||||
|
||||
/**
|
||||
* The stiffness of this equation. Typically chosen to a large number (~1e7), but can be chosen somewhat freely to get a stable simulation.
|
||||
* @property stiffness
|
||||
* @type {Number}
|
||||
*/
|
||||
* The stiffness of this equation. Typically chosen to a large number (~1e7), but can be chosen somewhat freely to get a stable simulation.
|
||||
* @property stiffness
|
||||
* @type {Number}
|
||||
*/
|
||||
this.stiffness = 1e6;
|
||||
|
||||
/**
|
||||
* The number of time steps needed to stabilize the constraint equation. Typically between 3 and 5 time steps.
|
||||
* @property relaxation
|
||||
* @type {Number}
|
||||
*/
|
||||
* The number of time steps needed to stabilize the constraint equation. Typically between 3 and 5 time steps.
|
||||
* @property relaxation
|
||||
* @type {Number}
|
||||
*/
|
||||
this.relaxation = 4;
|
||||
|
||||
this.a = 0;
|
||||
|
||||
@@ -31,24 +31,24 @@ function FrictionEquation(bi,bj,slipForce){
|
||||
Equation.call(this,bi,bj,-slipForce,slipForce);
|
||||
|
||||
/**
|
||||
* Relative vector from center of body i to the contact point, in world coords.
|
||||
* @property ri
|
||||
* @type {Float32Array}
|
||||
*/
|
||||
* Relative vector from center of body i to the contact point, in world coords.
|
||||
* @property ri
|
||||
* @type {Float32Array}
|
||||
*/
|
||||
this.ri = vec2.create();
|
||||
|
||||
/**
|
||||
* Relative vector from center of body j to the contact point, in world coords.
|
||||
* @property rj
|
||||
* @type {Float32Array}
|
||||
*/
|
||||
* Relative vector from center of body j to the contact point, in world coords.
|
||||
* @property rj
|
||||
* @type {Float32Array}
|
||||
*/
|
||||
this.rj = vec2.create();
|
||||
|
||||
/**
|
||||
* Tangent vector that the friction force will act along, in world coords.
|
||||
* @property t
|
||||
* @type {Float32Array}
|
||||
*/
|
||||
* Tangent vector that the friction force will act along, in world coords.
|
||||
* @property t
|
||||
* @type {Float32Array}
|
||||
*/
|
||||
this.t = vec2.create();
|
||||
|
||||
this.rixt = 0;
|
||||
|
||||
@@ -11,12 +11,12 @@ EventEmitter.prototype = {
|
||||
constructor: EventEmitter,
|
||||
|
||||
/**
|
||||
* Add an event listener
|
||||
* @method on
|
||||
* @param {String} type
|
||||
* @param {Function} listener
|
||||
* @return {EventEmitter} The self object, for chainability.
|
||||
*/
|
||||
* Add an event listener
|
||||
* @method on
|
||||
* @param {String} type
|
||||
* @param {Function} listener
|
||||
* @return {EventEmitter} The self object, for chainability.
|
||||
*/
|
||||
on: function ( type, listener ) {
|
||||
if ( this._listeners === undefined ) this._listeners = {};
|
||||
var listeners = this._listeners;
|
||||
@@ -30,12 +30,12 @@ EventEmitter.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Check if an event listener is added
|
||||
* @method has
|
||||
* @param {String} type
|
||||
* @param {Function} listener
|
||||
* @return {Boolean}
|
||||
*/
|
||||
* Check if an event listener is added
|
||||
* @method has
|
||||
* @param {String} type
|
||||
* @param {Function} listener
|
||||
* @return {Boolean}
|
||||
*/
|
||||
has: function ( type, listener ) {
|
||||
if ( this._listeners === undefined ) return false;
|
||||
var listeners = this._listeners;
|
||||
@@ -46,12 +46,12 @@ EventEmitter.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Remove an event listener
|
||||
* @method off
|
||||
* @param {String} type
|
||||
* @param {Function} listener
|
||||
* @return {EventEmitter} The self object, for chainability.
|
||||
*/
|
||||
* Remove an event listener
|
||||
* @method off
|
||||
* @param {String} type
|
||||
* @param {Function} listener
|
||||
* @return {EventEmitter} The self object, for chainability.
|
||||
*/
|
||||
off: function ( type, listener ) {
|
||||
if ( this._listeners === undefined ) return;
|
||||
var listeners = this._listeners;
|
||||
@@ -63,12 +63,12 @@ EventEmitter.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Emit an event.
|
||||
* @method emit
|
||||
* @param {Object} event
|
||||
* @param {String} event.type
|
||||
* @return {EventEmitter} The self object, for chainability.
|
||||
*/
|
||||
* Emit an event.
|
||||
* @method emit
|
||||
* @param {Object} event
|
||||
* @param {String} event.type
|
||||
* @return {EventEmitter} The self object, for chainability.
|
||||
*/
|
||||
emit: function ( event ) {
|
||||
if ( this._listeners === undefined ) return;
|
||||
var listeners = this._listeners;
|
||||
|
||||
@@ -17,65 +17,65 @@ function ContactMaterial(materialA, materialB, options){
|
||||
options = options || {};
|
||||
|
||||
/**
|
||||
* The contact material identifier
|
||||
* @property id
|
||||
* @type {Number}
|
||||
*/
|
||||
* The contact material identifier
|
||||
* @property id
|
||||
* @type {Number}
|
||||
*/
|
||||
this.id = idCounter++;
|
||||
|
||||
/**
|
||||
* First material participating in the contact material
|
||||
* @property materialA
|
||||
* @type {Material}
|
||||
*/
|
||||
* First material participating in the contact material
|
||||
* @property materialA
|
||||
* @type {Material}
|
||||
*/
|
||||
this.materialA = materialA;
|
||||
|
||||
/**
|
||||
* Second material participating in the contact material
|
||||
* @property materialB
|
||||
* @type {Material}
|
||||
*/
|
||||
* Second material participating in the contact material
|
||||
* @property materialB
|
||||
* @type {Material}
|
||||
*/
|
||||
this.materialB = materialB;
|
||||
|
||||
/**
|
||||
* Friction to use in the contact of these two materials
|
||||
* @property friction
|
||||
* @type {Number}
|
||||
*/
|
||||
* Friction to use in the contact of these two materials
|
||||
* @property friction
|
||||
* @type {Number}
|
||||
*/
|
||||
this.friction = typeof(options.friction) !== "undefined" ? Number(options.friction) : 0.3;
|
||||
|
||||
/**
|
||||
* Restitution to use in the contact of these two materials
|
||||
* @property restitution
|
||||
* @type {Number}
|
||||
*/
|
||||
* Restitution to use in the contact of these two materials
|
||||
* @property restitution
|
||||
* @type {Number}
|
||||
*/
|
||||
this.restitution = typeof(options.restitution) !== "undefined" ? Number(options.restitution) : 0.3;
|
||||
|
||||
/**
|
||||
* Stiffness of the resulting ContactEquation that this ContactMaterial generate
|
||||
* @property stiffness
|
||||
* @type {Number}
|
||||
*/
|
||||
* Stiffness of the resulting ContactEquation that this ContactMaterial generate
|
||||
* @property stiffness
|
||||
* @type {Number}
|
||||
*/
|
||||
this.stiffness = typeof(options.stiffness) !== "undefined" ? Number(options.stiffness) : 1e7;
|
||||
|
||||
/**
|
||||
* Relaxation of the resulting ContactEquation that this ContactMaterial generate
|
||||
* @property relaxation
|
||||
* @type {Number}
|
||||
*/
|
||||
* Relaxation of the resulting ContactEquation that this ContactMaterial generate
|
||||
* @property relaxation
|
||||
* @type {Number}
|
||||
*/
|
||||
this.relaxation = typeof(options.relaxation) !== "undefined" ? Number(options.relaxation) : 3;
|
||||
|
||||
/**
|
||||
* Stiffness of the resulting FrictionEquation that this ContactMaterial generate
|
||||
* @property frictionStiffness
|
||||
* @type {Number}
|
||||
*/
|
||||
* Stiffness of the resulting FrictionEquation that this ContactMaterial generate
|
||||
* @property frictionStiffness
|
||||
* @type {Number}
|
||||
*/
|
||||
this.frictionStiffness = typeof(options.frictionStiffness) !== "undefined" ? Number(options.frictionStiffness) : 1e7;
|
||||
|
||||
/**
|
||||
* Relaxation of the resulting FrictionEquation that this ContactMaterial generate
|
||||
* @property frictionRelaxation
|
||||
* @type {Number}
|
||||
*/
|
||||
* Relaxation of the resulting FrictionEquation that this ContactMaterial generate
|
||||
* @property frictionRelaxation
|
||||
* @type {Number}
|
||||
*/
|
||||
this.frictionRelaxation = typeof(options.frictionRelaxation) !== "undefined" ? Number(options.frictionRelaxation) : 3;
|
||||
};
|
||||
|
||||
@@ -11,9 +11,9 @@ var idCounter = 0;
|
||||
*/
|
||||
function Material(){
|
||||
/**
|
||||
* The material identifier
|
||||
* @property id
|
||||
* @type {Number}
|
||||
*/
|
||||
* The material identifier
|
||||
* @property id
|
||||
* @type {Number}
|
||||
*/
|
||||
this.id = idCounter++;
|
||||
};
|
||||
|
||||
@@ -472,6 +472,6 @@
|
||||
|
||||
PolyK._tp = [];
|
||||
for(var i=0; i<10; i++) PolyK._tp.push(new PolyK._P(0,0));
|
||||
*/
|
||||
*/
|
||||
|
||||
module.exports = PolyK;
|
||||
|
||||
@@ -25,155 +25,155 @@ function Body(options){
|
||||
options = options || {};
|
||||
|
||||
/**
|
||||
* The body identifyer
|
||||
* @property id
|
||||
* @type {Number}
|
||||
*/
|
||||
* The body identifyer
|
||||
* @property id
|
||||
* @type {Number}
|
||||
*/
|
||||
this.id = ++Body._idCounter;
|
||||
|
||||
/**
|
||||
* The shapes of the body. The local transform of the shape in .shapes[i] is
|
||||
* defined by .shapeOffsets[i] and .shapeAngles[i].
|
||||
*
|
||||
* @property shapes
|
||||
* @type {Array}
|
||||
*/
|
||||
* The shapes of the body. The local transform of the shape in .shapes[i] is
|
||||
* defined by .shapeOffsets[i] and .shapeAngles[i].
|
||||
*
|
||||
* @property shapes
|
||||
* @type {Array}
|
||||
*/
|
||||
this.shapes = [];
|
||||
|
||||
/**
|
||||
* The local shape offsets, relative to the body center of mass. This is an
|
||||
* array of Float32Array.
|
||||
* @property shapeOffsets
|
||||
* @type {Array}
|
||||
*/
|
||||
* The local shape offsets, relative to the body center of mass. This is an
|
||||
* array of Float32Array.
|
||||
* @property shapeOffsets
|
||||
* @type {Array}
|
||||
*/
|
||||
this.shapeOffsets = [];
|
||||
|
||||
/**
|
||||
* The body-local shape angle transforms. This is an array of numbers (angles).
|
||||
* @property shapeAngles
|
||||
* @type {Array}
|
||||
*/
|
||||
* The body-local shape angle transforms. This is an array of numbers (angles).
|
||||
* @property shapeAngles
|
||||
* @type {Array}
|
||||
*/
|
||||
this.shapeAngles = [];
|
||||
|
||||
/**
|
||||
* The mass of the body.
|
||||
* @property mass
|
||||
* @type {number}
|
||||
*/
|
||||
* The mass of the body.
|
||||
* @property mass
|
||||
* @type {number}
|
||||
*/
|
||||
this.mass = options.mass || 0;
|
||||
|
||||
/**
|
||||
* The inverse mass of the body.
|
||||
* @property invMass
|
||||
* @type {number}
|
||||
*/
|
||||
* The inverse mass of the body.
|
||||
* @property invMass
|
||||
* @type {number}
|
||||
*/
|
||||
this.invMass = 0;
|
||||
|
||||
/**
|
||||
* The inertia of the body around the Z axis.
|
||||
* @property inertia
|
||||
* @type {number}
|
||||
*/
|
||||
* The inertia of the body around the Z axis.
|
||||
* @property inertia
|
||||
* @type {number}
|
||||
*/
|
||||
this.inertia = 0;
|
||||
|
||||
/**
|
||||
* The inverse inertia of the body.
|
||||
* @property invInertia
|
||||
* @type {number}
|
||||
*/
|
||||
* The inverse inertia of the body.
|
||||
* @property invInertia
|
||||
* @type {number}
|
||||
*/
|
||||
this.invInertia = 0;
|
||||
|
||||
this.updateMassProperties();
|
||||
|
||||
/**
|
||||
* The position of the body
|
||||
* @property position
|
||||
* @type {Float32Array}
|
||||
*/
|
||||
* The position of the body
|
||||
* @property position
|
||||
* @type {Float32Array}
|
||||
*/
|
||||
this.position = vec2.fromValues(0,0);
|
||||
if(options.position) vec2.copy(this.position, options.position);
|
||||
|
||||
/**
|
||||
* The velocity of the body
|
||||
* @property velocity
|
||||
* @type {Float32Array}
|
||||
*/
|
||||
* The velocity of the body
|
||||
* @property velocity
|
||||
* @type {Float32Array}
|
||||
*/
|
||||
this.velocity = vec2.fromValues(0,0);
|
||||
if(options.velocity) vec2.copy(this.velocity, options.velocity);
|
||||
|
||||
/**
|
||||
* Constraint velocity that was added to the body during the last step.
|
||||
* @property vlambda
|
||||
* @type {Float32Array}
|
||||
*/
|
||||
* Constraint velocity that was added to the body during the last step.
|
||||
* @property vlambda
|
||||
* @type {Float32Array}
|
||||
*/
|
||||
this.vlambda = vec2.fromValues(0,0);
|
||||
|
||||
/**
|
||||
* Angular constraint velocity that was added to the body during last step.
|
||||
* @property wlambda
|
||||
* @type {Float32Array}
|
||||
*/
|
||||
* Angular constraint velocity that was added to the body during last step.
|
||||
* @property wlambda
|
||||
* @type {Float32Array}
|
||||
*/
|
||||
this.wlambda = 0;
|
||||
|
||||
/**
|
||||
* The angle of the body
|
||||
* @property angle
|
||||
* @type {number}
|
||||
*/
|
||||
* The angle of the body
|
||||
* @property angle
|
||||
* @type {number}
|
||||
*/
|
||||
this.angle = options.angle || 0;
|
||||
|
||||
/**
|
||||
* The angular velocity of the body
|
||||
* @property angularVelocity
|
||||
* @type {number}
|
||||
*/
|
||||
* The angular velocity of the body
|
||||
* @property angularVelocity
|
||||
* @type {number}
|
||||
*/
|
||||
this.angularVelocity = options.angularVelocity || 0;
|
||||
|
||||
/**
|
||||
* The force acting on the body
|
||||
* @property force
|
||||
* @type {Float32Array}
|
||||
*/
|
||||
* The force acting on the body
|
||||
* @property force
|
||||
* @type {Float32Array}
|
||||
*/
|
||||
this.force = vec2.create();
|
||||
if(options.force) vec2.copy(this.force, options.force);
|
||||
|
||||
/**
|
||||
* The angular force acting on the body
|
||||
* @property angularForce
|
||||
* @type {number}
|
||||
*/
|
||||
* The angular force acting on the body
|
||||
* @property angularForce
|
||||
* @type {number}
|
||||
*/
|
||||
this.angularForce = options.angularForce || 0;
|
||||
|
||||
/**
|
||||
* The type of motion this body has. Should be one of: Body.STATIC (the body
|
||||
* does not move), Body.DYNAMIC (body can move and respond to collisions)
|
||||
* and Body.KINEMATIC (only moves according to its .velocity).
|
||||
*
|
||||
* @property motionState
|
||||
* @type {number}
|
||||
*
|
||||
* @example
|
||||
* // This body will move and interact with other bodies
|
||||
* var dynamicBody = new Body();
|
||||
* dynamicBody.motionState = Body.DYNAMIC;
|
||||
*
|
||||
* @example
|
||||
* // This body will not move at all
|
||||
* var staticBody = new Body();
|
||||
* staticBody.motionState = Body.STATIC;
|
||||
*
|
||||
* @example
|
||||
* // This body will only move if you change its velocity
|
||||
* var kinematicBody = new Body();
|
||||
* kinematicBody.motionState = Body.KINEMATIC;
|
||||
*/
|
||||
* The type of motion this body has. Should be one of: Body.STATIC (the body
|
||||
* does not move), Body.DYNAMIC (body can move and respond to collisions)
|
||||
* and Body.KINEMATIC (only moves according to its .velocity).
|
||||
*
|
||||
* @property motionState
|
||||
* @type {number}
|
||||
*
|
||||
* @example
|
||||
* // This body will move and interact with other bodies
|
||||
* var dynamicBody = new Body();
|
||||
* dynamicBody.motionState = Body.DYNAMIC;
|
||||
*
|
||||
* @example
|
||||
* // This body will not move at all
|
||||
* var staticBody = new Body();
|
||||
* staticBody.motionState = Body.STATIC;
|
||||
*
|
||||
* @example
|
||||
* // This body will only move if you change its velocity
|
||||
* var kinematicBody = new Body();
|
||||
* kinematicBody.motionState = Body.KINEMATIC;
|
||||
*/
|
||||
this.motionState = this.mass === 0 ? Body.STATIC : Body.DYNAMIC;
|
||||
|
||||
/**
|
||||
* Bounding circle radius
|
||||
* @property boundingRadius
|
||||
* @type {Number}
|
||||
*/
|
||||
* Bounding circle radius
|
||||
* @property boundingRadius
|
||||
* @type {Number}
|
||||
*/
|
||||
this.boundingRadius = 0;
|
||||
};
|
||||
|
||||
|
||||
@@ -22,52 +22,52 @@ function Spring(bodyA,bodyB,options){
|
||||
options = options || {};
|
||||
|
||||
/**
|
||||
* Rest length of the spring.
|
||||
* @property restLength
|
||||
* @type {number}
|
||||
*/
|
||||
* Rest length of the spring.
|
||||
* @property restLength
|
||||
* @type {number}
|
||||
*/
|
||||
this.restLength = typeof(options.restLength)=="number" ? options.restLength : 1;
|
||||
|
||||
/**
|
||||
* Stiffness of the spring.
|
||||
* @property stiffness
|
||||
* @type {number}
|
||||
*/
|
||||
* Stiffness of the spring.
|
||||
* @property stiffness
|
||||
* @type {number}
|
||||
*/
|
||||
this.stiffness = options.stiffness || 100;
|
||||
|
||||
/**
|
||||
* Damping of the spring.
|
||||
* @property damping
|
||||
* @type {number}
|
||||
*/
|
||||
* Damping of the spring.
|
||||
* @property damping
|
||||
* @type {number}
|
||||
*/
|
||||
this.damping = options.damping || 1;
|
||||
|
||||
/**
|
||||
* First connected body.
|
||||
* @property bodyA
|
||||
* @type {Body}
|
||||
*/
|
||||
* First connected body.
|
||||
* @property bodyA
|
||||
* @type {Body}
|
||||
*/
|
||||
this.bodyA = bodyA;
|
||||
|
||||
/**
|
||||
* Second connected body.
|
||||
* @property bodyB
|
||||
* @type {Body}
|
||||
*/
|
||||
* Second connected body.
|
||||
* @property bodyB
|
||||
* @type {Body}
|
||||
*/
|
||||
this.bodyB = bodyB;
|
||||
|
||||
/**
|
||||
* Anchor for bodyA in local bodyA coordinates.
|
||||
* @property localAnchorA
|
||||
* @type {Array}
|
||||
*/
|
||||
* Anchor for bodyA in local bodyA coordinates.
|
||||
* @property localAnchorA
|
||||
* @type {Array}
|
||||
*/
|
||||
this.localAnchorA = vec2.fromValues(0,0);
|
||||
|
||||
/**
|
||||
* Anchor for bodyB in local bodyB coordinates.
|
||||
* @property localAnchorB
|
||||
* @type {Array}
|
||||
*/
|
||||
* Anchor for bodyB in local bodyB coordinates.
|
||||
* @property localAnchorB
|
||||
* @type {Array}
|
||||
*/
|
||||
this.localAnchorB = vec2.fromValues(0,0);
|
||||
|
||||
if(options.localAnchorA) vec2.copy(this.localAnchorA, options.localAnchorA);
|
||||
|
||||
@@ -12,10 +12,10 @@ module.exports = Circle;
|
||||
function Circle(radius){
|
||||
|
||||
/**
|
||||
* The radius of the circle.
|
||||
* @property radius
|
||||
* @type {number}
|
||||
*/
|
||||
* The radius of the circle.
|
||||
* @property radius
|
||||
* @type {number}
|
||||
*/
|
||||
this.radius = radius || 1;
|
||||
|
||||
Shape.call(this,Shape.CIRCLE);
|
||||
|
||||
@@ -14,24 +14,24 @@ module.exports = Convex;
|
||||
function Convex(vertices){
|
||||
|
||||
/**
|
||||
* Vertices defined in the local frame.
|
||||
* @property vertices
|
||||
* @type {Array}
|
||||
*/
|
||||
* Vertices defined in the local frame.
|
||||
* @property vertices
|
||||
* @type {Array}
|
||||
*/
|
||||
this.vertices = vertices || [];
|
||||
|
||||
/**
|
||||
* The center of mass of the Convex
|
||||
* @property centerOfMass
|
||||
* @type {Float32Array}
|
||||
*/
|
||||
* The center of mass of the Convex
|
||||
* @property centerOfMass
|
||||
* @type {Float32Array}
|
||||
*/
|
||||
this.centerOfMass = vec2.fromValues(0,0);
|
||||
|
||||
/**
|
||||
* Triangulated version of this convex. The structure is Array of 3-Arrays, and each subarray contains 3 integers, referencing the vertices.
|
||||
* @property triangles
|
||||
* @type {Array}
|
||||
*/
|
||||
* Triangulated version of this convex. The structure is Array of 3-Arrays, and each subarray contains 3 integers, referencing the vertices.
|
||||
* @property triangles
|
||||
* @type {Array}
|
||||
*/
|
||||
this.triangles = [];
|
||||
|
||||
if(this.vertices.length){
|
||||
@@ -40,10 +40,10 @@ function Convex(vertices){
|
||||
}
|
||||
|
||||
/**
|
||||
* The bounding radius of the convex
|
||||
* @property boundingRadius
|
||||
* @type {Number}
|
||||
*/
|
||||
* The bounding radius of the convex
|
||||
* @property boundingRadius
|
||||
* @type {Number}
|
||||
*/
|
||||
this.boundingRadius = 0;
|
||||
this.updateBoundingRadius();
|
||||
|
||||
|
||||
@@ -11,10 +11,10 @@ module.exports = Line;
|
||||
function Line(length){
|
||||
|
||||
/**
|
||||
* Length of this line
|
||||
* @property length
|
||||
* @type {Number}
|
||||
*/
|
||||
* Length of this line
|
||||
* @property length
|
||||
* @type {Number}
|
||||
*/
|
||||
this.length = length;
|
||||
|
||||
Shape.call(this,Shape.LINE);
|
||||
|
||||
@@ -9,56 +9,56 @@ function Shape(type){
|
||||
this.type = type;
|
||||
|
||||
/**
|
||||
* Bounding circle radius of this shape
|
||||
* @property boundingRadius
|
||||
* @type {Number}
|
||||
*/
|
||||
* Bounding circle radius of this shape
|
||||
* @property boundingRadius
|
||||
* @type {Number}
|
||||
*/
|
||||
this.boundingRadius = 0;
|
||||
|
||||
/**
|
||||
* Collision group that this shape belongs to (bit mask). See <a href="http://www.aurelienribon.com/blog/2011/07/box2d-tutorial-collision-filtering/">this tutorial</a>.
|
||||
* @property collisionGroup
|
||||
* @type {Number}
|
||||
* @example
|
||||
* // Setup bits for each available group
|
||||
* var PLAYER = Math.pow(2,0),
|
||||
* ENEMY = Math.pow(2,1),
|
||||
* GROUND = Math.pow(2,2)
|
||||
*
|
||||
* // Put shapes into their groups
|
||||
* player1Shape.collisionGroup = PLAYER;
|
||||
* player2Shape.collisionGroup = PLAYER;
|
||||
* enemyShape .collisionGroup = ENEMY;
|
||||
* groundShape .collisionGroup = GROUND;
|
||||
*
|
||||
* // Assign groups that each shape collide with.
|
||||
* // Note that the players can collide with ground and enemies, but not with other players.
|
||||
* player1Shape.collisionMask = ENEMY | GROUND;
|
||||
* player2Shape.collisionMask = ENEMY | GROUND;
|
||||
* enemyShape .collisionMask = PLAYER | GROUND;
|
||||
* groundShape .collisionMask = PLAYER | ENEMY;
|
||||
*
|
||||
* @example
|
||||
* // How collision check is done
|
||||
* if(shapeA.collisionGroup & shapeB.collisionMask)!=0 && (shapeB.collisionGroup & shapeA.collisionMask)!=0){
|
||||
* // The shapes will collide
|
||||
* }
|
||||
*/
|
||||
* Collision group that this shape belongs to (bit mask). See <a href="http://www.aurelienribon.com/blog/2011/07/box2d-tutorial-collision-filtering/">this tutorial</a>.
|
||||
* @property collisionGroup
|
||||
* @type {Number}
|
||||
* @example
|
||||
* // Setup bits for each available group
|
||||
* var PLAYER = Math.pow(2,0),
|
||||
* ENEMY = Math.pow(2,1),
|
||||
* GROUND = Math.pow(2,2)
|
||||
*
|
||||
* // Put shapes into their groups
|
||||
* player1Shape.collisionGroup = PLAYER;
|
||||
* player2Shape.collisionGroup = PLAYER;
|
||||
* enemyShape .collisionGroup = ENEMY;
|
||||
* groundShape .collisionGroup = GROUND;
|
||||
*
|
||||
* // Assign groups that each shape collide with.
|
||||
* // Note that the players can collide with ground and enemies, but not with other players.
|
||||
* player1Shape.collisionMask = ENEMY | GROUND;
|
||||
* player2Shape.collisionMask = ENEMY | GROUND;
|
||||
* enemyShape .collisionMask = PLAYER | GROUND;
|
||||
* groundShape .collisionMask = PLAYER | ENEMY;
|
||||
*
|
||||
* @example
|
||||
* // How collision check is done
|
||||
* if(shapeA.collisionGroup & shapeB.collisionMask)!=0 && (shapeB.collisionGroup & shapeA.collisionMask)!=0){
|
||||
* // The shapes will collide
|
||||
* }
|
||||
*/
|
||||
this.collisionGroup = 1;
|
||||
|
||||
/**
|
||||
* Collision mask of this shape. See .collisionGroup.
|
||||
* @property collisionMask
|
||||
* @type {Number}
|
||||
*/
|
||||
* Collision mask of this shape. See .collisionGroup.
|
||||
* @property collisionMask
|
||||
* @type {Number}
|
||||
*/
|
||||
this.collisionMask = 1;
|
||||
if(type) this.updateBoundingRadius();
|
||||
|
||||
/**
|
||||
* Material to use in collisions for this Shape. If this is set to null, the world will use default material properties instead.
|
||||
* @property material
|
||||
* @type {Material}
|
||||
*/
|
||||
* Material to use in collisions for this Shape. If this is set to null, the world will use default material properties instead.
|
||||
* @property material
|
||||
* @type {Material}
|
||||
*/
|
||||
this.material = null;
|
||||
};
|
||||
|
||||
|
||||
@@ -30,31 +30,31 @@ function GSSolver(options){
|
||||
this.invCs = new ARRAY_TYPE(this.arrayStep);
|
||||
|
||||
/**
|
||||
* Whether to use .stiffness and .relaxation parameters from the Solver instead of each Equation individually.
|
||||
* @type {Boolean}
|
||||
* @property useGlobalEquationParameters
|
||||
*/
|
||||
* Whether to use .stiffness and .relaxation parameters from the Solver instead of each Equation individually.
|
||||
* @type {Boolean}
|
||||
* @property useGlobalEquationParameters
|
||||
*/
|
||||
this.useGlobalEquationParameters = true;
|
||||
|
||||
/**
|
||||
* Global equation stiffness.
|
||||
* @property stiffness
|
||||
* @type {Number}
|
||||
*/
|
||||
* Global equation stiffness.
|
||||
* @property stiffness
|
||||
* @type {Number}
|
||||
*/
|
||||
this.stiffness = 1e6;
|
||||
|
||||
/**
|
||||
* Global equation relaxation.
|
||||
* @property relaxation
|
||||
* @type {Number}
|
||||
*/
|
||||
* Global equation relaxation.
|
||||
* @property relaxation
|
||||
* @type {Number}
|
||||
*/
|
||||
this.relaxation = 4;
|
||||
|
||||
/**
|
||||
* Set to true to set all right hand side terms to zero when solving. Can be handy for a few applications.
|
||||
* @property useZeroRHS
|
||||
* @type {Boolean}
|
||||
*/
|
||||
* Set to true to set all right hand side terms to zero when solving. Can be handy for a few applications.
|
||||
* @property useZeroRHS
|
||||
* @type {Boolean}
|
||||
*/
|
||||
this.useZeroRHS = false;
|
||||
};
|
||||
GSSolver.prototype = new Solver();
|
||||
|
||||
@@ -8,17 +8,17 @@ module.exports = Island;
|
||||
function Island(){
|
||||
|
||||
/**
|
||||
* Current equations in this island.
|
||||
* @property equations
|
||||
* @type {Array}
|
||||
*/
|
||||
* Current equations in this island.
|
||||
* @property equations
|
||||
* @type {Array}
|
||||
*/
|
||||
this.equations = [];
|
||||
|
||||
/**
|
||||
* Current bodies in this island.
|
||||
* @property bodies
|
||||
* @type {Array}
|
||||
*/
|
||||
* Current bodies in this island.
|
||||
* @property bodies
|
||||
* @type {Array}
|
||||
*/
|
||||
this.bodies = [];
|
||||
}
|
||||
|
||||
|
||||
@@ -19,17 +19,17 @@ function IslandSolver(subsolver){
|
||||
var that = this;
|
||||
|
||||
/**
|
||||
* The solver used in the workers.
|
||||
* @property subsolver
|
||||
* @type {Solver}
|
||||
*/
|
||||
* The solver used in the workers.
|
||||
* @property subsolver
|
||||
* @type {Solver}
|
||||
*/
|
||||
this.subsolver = subsolver;
|
||||
|
||||
/**
|
||||
* Number of islands
|
||||
* @property numIslands
|
||||
* @type {number}
|
||||
*/
|
||||
* Number of islands
|
||||
* @property numIslands
|
||||
* @type {number}
|
||||
*/
|
||||
this.numIslands = 0;
|
||||
|
||||
// Pooling of node objects saves some GC load
|
||||
|
||||
@@ -10,11 +10,11 @@ module.exports = Solver;
|
||||
function Solver(){
|
||||
|
||||
/**
|
||||
* Current equations in the solver.
|
||||
*
|
||||
* @property equations
|
||||
* @type {Array}
|
||||
*/
|
||||
* Current equations in the solver.
|
||||
*
|
||||
* @property equations
|
||||
* @type {Array}
|
||||
*/
|
||||
this.equations = [];
|
||||
};
|
||||
|
||||
|
||||
@@ -48,110 +48,110 @@ function World(options){
|
||||
options = options || {};
|
||||
|
||||
/**
|
||||
* All springs in the world.
|
||||
*
|
||||
* @property springs
|
||||
* @type {Array}
|
||||
*/
|
||||
* All springs in the world.
|
||||
*
|
||||
* @property springs
|
||||
* @type {Array}
|
||||
*/
|
||||
this.springs = [];
|
||||
|
||||
/**
|
||||
* All bodies in the world.
|
||||
*
|
||||
* @property bodies
|
||||
* @type {Array}
|
||||
*/
|
||||
* All bodies in the world.
|
||||
*
|
||||
* @property bodies
|
||||
* @type {Array}
|
||||
*/
|
||||
this.bodies = [];
|
||||
|
||||
/**
|
||||
* The solver used to satisfy constraints and contacts.
|
||||
*
|
||||
* @property solver
|
||||
* @type {Solver}
|
||||
*/
|
||||
* The solver used to satisfy constraints and contacts.
|
||||
*
|
||||
* @property solver
|
||||
* @type {Solver}
|
||||
*/
|
||||
this.solver = options.solver || new GSSolver();
|
||||
|
||||
/**
|
||||
* The nearphase to use to generate contacts.
|
||||
*
|
||||
* @property nearphase
|
||||
* @type {Nearphase}
|
||||
*/
|
||||
* The nearphase to use to generate contacts.
|
||||
*
|
||||
* @property nearphase
|
||||
* @type {Nearphase}
|
||||
*/
|
||||
this.nearphase = new Nearphase();
|
||||
|
||||
/**
|
||||
* Gravity in the world. This is applied on all bodies in the beginning of each step().
|
||||
*
|
||||
* @property
|
||||
* @type {Float32Array}
|
||||
*/
|
||||
* Gravity in the world. This is applied on all bodies in the beginning of each step().
|
||||
*
|
||||
* @property
|
||||
* @type {Float32Array}
|
||||
*/
|
||||
this.gravity = options.gravity || vec2.fromValues(0, -9.78);
|
||||
|
||||
/**
|
||||
* Whether to do timing measurements during the step() or not.
|
||||
*
|
||||
* @property doPofiling
|
||||
* @type {Boolean}
|
||||
*/
|
||||
* Whether to do timing measurements during the step() or not.
|
||||
*
|
||||
* @property doPofiling
|
||||
* @type {Boolean}
|
||||
*/
|
||||
this.doProfiling = options.doProfiling || false;
|
||||
|
||||
/**
|
||||
* How many millisecconds the last step() took. This is updated each step if .doProfiling is set to true.
|
||||
*
|
||||
* @property lastStepTime
|
||||
* @type {Number}
|
||||
*/
|
||||
* How many millisecconds the last step() took. This is updated each step if .doProfiling is set to true.
|
||||
*
|
||||
* @property lastStepTime
|
||||
* @type {Number}
|
||||
*/
|
||||
this.lastStepTime = 0.0;
|
||||
|
||||
/**
|
||||
* The broadphase algorithm to use.
|
||||
*
|
||||
* @property broadphase
|
||||
* @type {Broadphase}
|
||||
*/
|
||||
* The broadphase algorithm to use.
|
||||
*
|
||||
* @property broadphase
|
||||
* @type {Broadphase}
|
||||
*/
|
||||
this.broadphase = options.broadphase || new NaiveBroadphase();
|
||||
|
||||
/**
|
||||
* User-added constraints.
|
||||
*
|
||||
* @property constraints
|
||||
* @type {Array}
|
||||
*/
|
||||
* User-added constraints.
|
||||
*
|
||||
* @property constraints
|
||||
* @type {Array}
|
||||
*/
|
||||
this.constraints = [];
|
||||
|
||||
/**
|
||||
* Friction between colliding bodies. This value is used if no matching ContactMaterial is found for the body pair.
|
||||
* @property defaultFriction
|
||||
* @type {Number}
|
||||
*/
|
||||
* Friction between colliding bodies. This value is used if no matching ContactMaterial is found for the body pair.
|
||||
* @property defaultFriction
|
||||
* @type {Number}
|
||||
*/
|
||||
this.defaultFriction = 0.1;
|
||||
|
||||
/**
|
||||
* For keeping track of what time step size we used last step
|
||||
* @property lastTimeStep
|
||||
* @type {Number}
|
||||
*/
|
||||
* For keeping track of what time step size we used last step
|
||||
* @property lastTimeStep
|
||||
* @type {Number}
|
||||
*/
|
||||
this.lastTimeStep = 1/60;
|
||||
|
||||
/**
|
||||
* Enable to automatically apply spring forces each step.
|
||||
* @property applySpringForces
|
||||
* @type {Boolean}
|
||||
*/
|
||||
* Enable to automatically apply spring forces each step.
|
||||
* @property applySpringForces
|
||||
* @type {Boolean}
|
||||
*/
|
||||
this.applySpringForces = true;
|
||||
|
||||
/**
|
||||
* Enable/disable constraint solving in each step.
|
||||
* @property solveConstraints
|
||||
* @type {Boolean}
|
||||
*/
|
||||
* Enable/disable constraint solving in each step.
|
||||
* @property solveConstraints
|
||||
* @type {Boolean}
|
||||
*/
|
||||
this.solveConstraints = true;
|
||||
|
||||
/**
|
||||
* The ContactMaterials added to the World.
|
||||
* @property contactMaterials
|
||||
* @type {Array}
|
||||
*/
|
||||
* The ContactMaterials added to the World.
|
||||
* @property contactMaterials
|
||||
* @type {Array}
|
||||
*/
|
||||
this.contactMaterials = [];
|
||||
|
||||
// Id counters
|
||||
|
||||
@@ -27,7 +27,7 @@ Phaser.Physics.Arcade = function (game) {
|
||||
/**
|
||||
* @property {Phaser.Point} gravity - The World gravity setting. Defaults to x: 0, y: 0, or no gravity.
|
||||
*/
|
||||
this.gravity = new Phaser.Point;
|
||||
this.gravity = new Phaser.Point();
|
||||
|
||||
/**
|
||||
* @property {Phaser.Rectangle} bounds - The bounds inside of which the physics world exists. Defaults to match the world bounds.
|
||||
@@ -65,13 +65,13 @@ Phaser.Physics.Arcade = function (game) {
|
||||
* @property {Phaser.Rectangle} _bounds1 - Internal cache var.
|
||||
* @private
|
||||
*/
|
||||
this._bounds1 = new Phaser.Rectangle;
|
||||
this._bounds1 = new Phaser.Rectangle();
|
||||
|
||||
/**
|
||||
* @property {Phaser.Rectangle} _bounds2 - Internal cache var.
|
||||
* @private
|
||||
*/
|
||||
this._bounds2 = new Phaser.Rectangle;
|
||||
this._bounds2 = new Phaser.Rectangle();
|
||||
|
||||
/**
|
||||
* @property {number} _overlap - Internal cache var.
|
||||
@@ -462,7 +462,7 @@ Phaser.Physics.Arcade.prototype = {
|
||||
{
|
||||
var currentNode = group._container.first._iNext;
|
||||
|
||||
do
|
||||
do
|
||||
{
|
||||
if (currentNode.exists)
|
||||
{
|
||||
@@ -572,7 +572,7 @@ Phaser.Physics.Arcade.prototype = {
|
||||
{
|
||||
var currentNode = group1._container.first._iNext;
|
||||
|
||||
do
|
||||
do
|
||||
{
|
||||
if (currentNode.exists)
|
||||
{
|
||||
@@ -658,7 +658,7 @@ Phaser.Physics.Arcade.prototype = {
|
||||
}
|
||||
|
||||
// Then adjust their positions and velocities accordingly (if there was any overlap)
|
||||
if (this._overlap != 0)
|
||||
if (this._overlap !== 0)
|
||||
{
|
||||
body1.overlapX = this._overlap;
|
||||
body2.overlapX = this._overlap;
|
||||
@@ -766,7 +766,7 @@ Phaser.Physics.Arcade.prototype = {
|
||||
}
|
||||
|
||||
// Then adjust their positions and velocities accordingly (if there was any overlap)
|
||||
if (this._overlap != 0)
|
||||
if (this._overlap !== 0)
|
||||
{
|
||||
body1.overlapY = this._overlap;
|
||||
body2.overlapY = this._overlap;
|
||||
@@ -894,7 +894,7 @@ Phaser.Physics.Arcade.prototype = {
|
||||
}
|
||||
|
||||
// Then adjust their positions and velocities accordingly (if there was any overlap)
|
||||
if (this._overlap != 0)
|
||||
if (this._overlap !== 0)
|
||||
{
|
||||
if (separate)
|
||||
{
|
||||
@@ -980,7 +980,7 @@ Phaser.Physics.Arcade.prototype = {
|
||||
}
|
||||
|
||||
// Then adjust their positions and velocities accordingly (if there was any overlap)
|
||||
if (this._overlap != 0)
|
||||
if (this._overlap !== 0)
|
||||
{
|
||||
if (separate)
|
||||
{
|
||||
@@ -1133,7 +1133,7 @@ Phaser.Physics.Arcade.prototype = {
|
||||
velocityFromAngle: function (angle, speed, point) {
|
||||
|
||||
if (typeof speed === 'undefined') { speed = 60; }
|
||||
point = point || new Phaser.Point;
|
||||
point = point || new Phaser.Point();
|
||||
|
||||
return point.setTo((Math.cos(this.game.math.degToRad(angle)) * speed), (Math.sin(this.game.math.degToRad(angle)) * speed));
|
||||
|
||||
@@ -1152,7 +1152,7 @@ Phaser.Physics.Arcade.prototype = {
|
||||
velocityFromRotation: function (rotation, speed, point) {
|
||||
|
||||
if (typeof speed === 'undefined') { speed = 60; }
|
||||
point = point || new Phaser.Point;
|
||||
point = point || new Phaser.Point();
|
||||
|
||||
return point.setTo((Math.cos(rotation) * speed), (Math.sin(rotation) * speed));
|
||||
|
||||
@@ -1171,7 +1171,7 @@ Phaser.Physics.Arcade.prototype = {
|
||||
accelerationFromRotation: function (rotation, speed, point) {
|
||||
|
||||
if (typeof speed === 'undefined') { speed = 60; }
|
||||
point = point || new Phaser.Point;
|
||||
point = point || new Phaser.Point();
|
||||
|
||||
return point.setTo((Math.cos(rotation) * speed), (Math.sin(rotation) * speed));
|
||||
|
||||
|
||||
+140
-140
@@ -18,91 +18,91 @@ Phaser.Physics.Arcade.Body = function (sprite) {
|
||||
/**
|
||||
* @property {Phaser.Sprite} sprite - Reference to the parent Sprite.
|
||||
*/
|
||||
this.sprite = sprite;
|
||||
this.sprite = sprite;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Game} game - Local reference to game.
|
||||
*/
|
||||
this.game = sprite.game;
|
||||
this.game = sprite.game;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Point} offset - The offset of the Physics Body from the Sprite x/y position.
|
||||
*/
|
||||
this.offset = new Phaser.Point;
|
||||
this.offset = new Phaser.Point();
|
||||
|
||||
/**
|
||||
* @property {number} x - The x position of the physics body.
|
||||
* @readonly
|
||||
*/
|
||||
this.x = sprite.x;
|
||||
this.x = sprite.x;
|
||||
|
||||
/**
|
||||
* @property {number} y - The y position of the physics body.
|
||||
* @readonly
|
||||
*/
|
||||
this.y = sprite.y;
|
||||
this.y = sprite.y;
|
||||
|
||||
/**
|
||||
* @property {number} preX - The previous x position of the physics body.
|
||||
* @readonly
|
||||
*/
|
||||
this.preX = sprite.x;
|
||||
this.preX = sprite.x;
|
||||
|
||||
/**
|
||||
* @property {number} preY - The previous y position of the physics body.
|
||||
* @readonly
|
||||
*/
|
||||
this.preY = sprite.y;
|
||||
this.preY = sprite.y;
|
||||
|
||||
/**
|
||||
* @property {number} preRotation - The previous rotation of the physics body.
|
||||
* @readonly
|
||||
*/
|
||||
this.preRotation = sprite.angle;
|
||||
this.preRotation = sprite.angle;
|
||||
|
||||
/**
|
||||
* @property {number} screenX - The x position of the physics body translated to screen space.
|
||||
* @readonly
|
||||
*/
|
||||
this.screenX = sprite.x;
|
||||
this.screenX = sprite.x;
|
||||
|
||||
/**
|
||||
* @property {number} screenY - The y position of the physics body translated to screen space.
|
||||
* @readonly
|
||||
*/
|
||||
this.screenY = sprite.y;
|
||||
this.screenY = sprite.y;
|
||||
|
||||
/**
|
||||
* @property {number} sourceWidth - The un-scaled original size.
|
||||
* @readonly
|
||||
*/
|
||||
this.sourceWidth = sprite.currentFrame.sourceSizeW;
|
||||
this.sourceWidth = sprite.currentFrame.sourceSizeW;
|
||||
|
||||
/**
|
||||
* @property {number} sourceHeight - The un-scaled original size.
|
||||
* @readonly
|
||||
*/
|
||||
this.sourceHeight = sprite.currentFrame.sourceSizeH;
|
||||
this.sourceHeight = sprite.currentFrame.sourceSizeH;
|
||||
|
||||
/**
|
||||
* @property {number} width - The calculated width of the physics body.
|
||||
*/
|
||||
this.width = sprite.currentFrame.sourceSizeW;
|
||||
this.width = sprite.currentFrame.sourceSizeW;
|
||||
|
||||
/**
|
||||
* @property .numInternal ID cache
|
||||
*/
|
||||
this.height = sprite.currentFrame.sourceSizeH;
|
||||
this.height = sprite.currentFrame.sourceSizeH;
|
||||
|
||||
/**
|
||||
* @property {number} halfWidth - The calculated width / 2 of the physics body.
|
||||
*/
|
||||
this.halfWidth = Math.floor(sprite.currentFrame.sourceSizeW / 2);
|
||||
this.halfWidth = Math.floor(sprite.currentFrame.sourceSizeW / 2);
|
||||
|
||||
/**
|
||||
* @property {number} halfHeight - The calculated height / 2 of the physics body.
|
||||
*/
|
||||
this.halfHeight = Math.floor(sprite.currentFrame.sourceSizeH / 2);
|
||||
this.halfHeight = Math.floor(sprite.currentFrame.sourceSizeH / 2);
|
||||
|
||||
/**
|
||||
* @property {Phaser.Point} center - The center coordinate of the Physics Body.
|
||||
@@ -113,38 +113,38 @@ Phaser.Physics.Arcade.Body = function (sprite) {
|
||||
* @property {number} _sx - Internal cache var.
|
||||
* @private
|
||||
*/
|
||||
this._sx = sprite.scale.x;
|
||||
this._sx = sprite.scale.x;
|
||||
|
||||
/**
|
||||
* @property {number} _sy - Internal cache var.
|
||||
* @private
|
||||
*/
|
||||
this._sy = sprite.scale.y;
|
||||
this._sy = sprite.scale.y;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Point} velocity - The velocity in pixels per second sq. of the Body.
|
||||
*/
|
||||
this.velocity = new Phaser.Point;
|
||||
this.velocity = new Phaser.Point();
|
||||
|
||||
/**
|
||||
* @property {Phaser.Point} acceleration - The velocity in pixels per second sq. of the Body.
|
||||
*/
|
||||
this.acceleration = new Phaser.Point;
|
||||
this.acceleration = new Phaser.Point();
|
||||
|
||||
/**
|
||||
* @property {Phaser.Point} drag - The drag applied to the motion of the Body.
|
||||
*/
|
||||
this.drag = new Phaser.Point;
|
||||
this.drag = new Phaser.Point();
|
||||
|
||||
/**
|
||||
* @property {Phaser.Point} gravity - A private Gravity setting for the Body.
|
||||
*/
|
||||
this.gravity = new Phaser.Point;
|
||||
this.gravity = new Phaser.Point();
|
||||
|
||||
/**
|
||||
* @property {Phaser.Point} bounce - The elasticitiy of the Body when colliding. bounce.x/y = 1 means full rebound, bounce.x/y = 0.5 means 50% rebound velocity.
|
||||
*/
|
||||
this.bounce = new Phaser.Point;
|
||||
this.bounce = new Phaser.Point();
|
||||
|
||||
/**
|
||||
* @property {Phaser.Point} maxVelocity - The maximum velocity in pixels per second sq. that the Body can reach.
|
||||
@@ -200,7 +200,7 @@ Phaser.Physics.Arcade.Body = function (sprite) {
|
||||
*/
|
||||
this.quadTreeIndex = -1;
|
||||
|
||||
// Allow collision
|
||||
// Allow collision
|
||||
|
||||
/**
|
||||
* Set the allowCollision properties to control which directions collision is processed for this Body.
|
||||
@@ -318,20 +318,20 @@ Phaser.Physics.Arcade.Body.prototype = {
|
||||
* @method Phaser.Physics.Arcade#updateBounds
|
||||
* @protected
|
||||
*/
|
||||
updateBounds: function (centerX, centerY, scaleX, scaleY) {
|
||||
updateBounds: function (centerX, centerY, scaleX, scaleY) {
|
||||
|
||||
if (scaleX != this._sx || scaleY != this._sy)
|
||||
{
|
||||
this.width = this.sourceWidth * scaleX;
|
||||
this.height = this.sourceHeight * scaleY;
|
||||
this.halfWidth = Math.floor(this.width / 2);
|
||||
this.halfHeight = Math.floor(this.height / 2);
|
||||
this._sx = scaleX;
|
||||
this._sy = scaleY;
|
||||
if (scaleX != this._sx || scaleY != this._sy)
|
||||
{
|
||||
this.width = this.sourceWidth * scaleX;
|
||||
this.height = this.sourceHeight * scaleY;
|
||||
this.halfWidth = Math.floor(this.width / 2);
|
||||
this.halfHeight = Math.floor(this.height / 2);
|
||||
this._sx = scaleX;
|
||||
this._sy = scaleY;
|
||||
this.center.setTo(this.x + this.halfWidth, this.y + this.halfHeight);
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
* Internal method.
|
||||
@@ -339,55 +339,55 @@ Phaser.Physics.Arcade.Body.prototype = {
|
||||
* @method Phaser.Physics.Arcade#preUpdate
|
||||
* @protected
|
||||
*/
|
||||
preUpdate: function () {
|
||||
preUpdate: function () {
|
||||
|
||||
// Store and reset collision flags
|
||||
this.wasTouching.none = this.touching.none;
|
||||
this.wasTouching.up = this.touching.up;
|
||||
this.wasTouching.down = this.touching.down;
|
||||
this.wasTouching.left = this.touching.left;
|
||||
this.wasTouching.right = this.touching.right;
|
||||
// Store and reset collision flags
|
||||
this.wasTouching.none = this.touching.none;
|
||||
this.wasTouching.up = this.touching.up;
|
||||
this.wasTouching.down = this.touching.down;
|
||||
this.wasTouching.left = this.touching.left;
|
||||
this.wasTouching.right = this.touching.right;
|
||||
|
||||
this.touching.none = true;
|
||||
this.touching.up = false;
|
||||
this.touching.down = false;
|
||||
this.touching.left = false;
|
||||
this.touching.right = false;
|
||||
this.touching.none = true;
|
||||
this.touching.up = false;
|
||||
this.touching.down = false;
|
||||
this.touching.left = false;
|
||||
this.touching.right = false;
|
||||
|
||||
this.embedded = false;
|
||||
this.embedded = false;
|
||||
|
||||
this.screenX = (this.sprite.worldTransform[2] - (this.sprite.anchor.x * this.width)) + this.offset.x;
|
||||
this.screenY = (this.sprite.worldTransform[5] - (this.sprite.anchor.y * this.height)) + this.offset.y;
|
||||
this.screenX = (this.sprite.worldTransform[2] - (this.sprite.anchor.x * this.width)) + this.offset.x;
|
||||
this.screenY = (this.sprite.worldTransform[5] - (this.sprite.anchor.y * this.height)) + this.offset.y;
|
||||
|
||||
this.preX = (this.sprite.world.x - (this.sprite.anchor.x * this.width)) + this.offset.x;
|
||||
this.preY = (this.sprite.world.y - (this.sprite.anchor.y * this.height)) + this.offset.y;
|
||||
|
||||
this.preRotation = this.sprite.angle;
|
||||
this.preRotation = this.sprite.angle;
|
||||
|
||||
this.x = this.preX;
|
||||
this.y = this.preY;
|
||||
this.rotation = this.preRotation;
|
||||
this.x = this.preX;
|
||||
this.y = this.preY;
|
||||
this.rotation = this.preRotation;
|
||||
|
||||
if (this.moves)
|
||||
{
|
||||
this.game.physics.updateMotion(this);
|
||||
if (this.moves)
|
||||
{
|
||||
this.game.physics.updateMotion(this);
|
||||
|
||||
if (this.collideWorldBounds)
|
||||
{
|
||||
this.checkWorldBounds();
|
||||
}
|
||||
if (this.collideWorldBounds)
|
||||
{
|
||||
this.checkWorldBounds();
|
||||
}
|
||||
|
||||
this.updateHulls();
|
||||
this.updateHulls();
|
||||
}
|
||||
|
||||
if (this.skipQuadTree === false && this.allowCollision.none === false && this.sprite.visible && this.sprite.alive)
|
||||
{
|
||||
this.quadTreeIDs = [];
|
||||
this.quadTreeIndex = -1;
|
||||
this.game.physics.quadTree.insert(this);
|
||||
}
|
||||
if (this.skipQuadTree === false && this.allowCollision.none === false && this.sprite.visible && this.sprite.alive)
|
||||
{
|
||||
this.quadTreeIDs = [];
|
||||
this.quadTreeIndex = -1;
|
||||
this.game.physics.quadTree.insert(this);
|
||||
}
|
||||
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
* Internal method.
|
||||
@@ -395,25 +395,25 @@ Phaser.Physics.Arcade.Body.prototype = {
|
||||
* @method Phaser.Physics.Arcade#postUpdate
|
||||
* @protected
|
||||
*/
|
||||
postUpdate: function () {
|
||||
postUpdate: function () {
|
||||
|
||||
if (this.deltaX() < 0)
|
||||
{
|
||||
this.facing = Phaser.LEFT;
|
||||
}
|
||||
else if (this.deltaX() > 0)
|
||||
{
|
||||
this.facing = Phaser.RIGHT;
|
||||
}
|
||||
if (this.deltaX() < 0)
|
||||
{
|
||||
this.facing = Phaser.LEFT;
|
||||
}
|
||||
else if (this.deltaX() > 0)
|
||||
{
|
||||
this.facing = Phaser.RIGHT;
|
||||
}
|
||||
|
||||
if (this.deltaY() < 0)
|
||||
{
|
||||
this.facing = Phaser.UP;
|
||||
}
|
||||
else if (this.deltaY() > 0)
|
||||
{
|
||||
this.facing = Phaser.DOWN;
|
||||
}
|
||||
if (this.deltaY() < 0)
|
||||
{
|
||||
this.facing = Phaser.UP;
|
||||
}
|
||||
else if (this.deltaY() > 0)
|
||||
{
|
||||
this.facing = Phaser.DOWN;
|
||||
}
|
||||
|
||||
if (this.deltaX() !== 0 || this.deltaY() !== 0)
|
||||
{
|
||||
@@ -422,12 +422,12 @@ Phaser.Physics.Arcade.Body.prototype = {
|
||||
this.center.setTo(this.x + this.halfWidth, this.y + this.halfHeight);
|
||||
}
|
||||
|
||||
if (this.allowRotation)
|
||||
{
|
||||
this.sprite.angle += this.deltaZ();
|
||||
}
|
||||
if (this.allowRotation)
|
||||
{
|
||||
this.sprite.angle += this.deltaZ();
|
||||
}
|
||||
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
* Internal method.
|
||||
@@ -435,12 +435,12 @@ Phaser.Physics.Arcade.Body.prototype = {
|
||||
* @method Phaser.Physics.Arcade#updateHulls
|
||||
* @protected
|
||||
*/
|
||||
updateHulls: function () {
|
||||
updateHulls: function () {
|
||||
|
||||
this.hullX.setTo(this.x, this.preY, this.width, this.height);
|
||||
this.hullY.setTo(this.preX, this.y, this.width, this.height);
|
||||
this.hullX.setTo(this.x, this.preY, this.width, this.height);
|
||||
this.hullY.setTo(this.preX, this.y, this.width, this.height);
|
||||
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
* Internal method.
|
||||
@@ -448,31 +448,31 @@ Phaser.Physics.Arcade.Body.prototype = {
|
||||
* @method Phaser.Physics.Arcade#checkWorldBounds
|
||||
* @protected
|
||||
*/
|
||||
checkWorldBounds: function () {
|
||||
checkWorldBounds: function () {
|
||||
|
||||
if (this.x < this.game.world.bounds.x)
|
||||
{
|
||||
this.x = this.game.world.bounds.x;
|
||||
this.velocity.x *= -this.bounce.x;
|
||||
}
|
||||
else if (this.right > this.game.world.bounds.right)
|
||||
{
|
||||
this.x = this.game.world.bounds.right - this.width;
|
||||
this.velocity.x *= -this.bounce.x;
|
||||
}
|
||||
if (this.x < this.game.world.bounds.x)
|
||||
{
|
||||
this.x = this.game.world.bounds.x;
|
||||
this.velocity.x *= -this.bounce.x;
|
||||
}
|
||||
else if (this.right > this.game.world.bounds.right)
|
||||
{
|
||||
this.x = this.game.world.bounds.right - this.width;
|
||||
this.velocity.x *= -this.bounce.x;
|
||||
}
|
||||
|
||||
if (this.y < this.game.world.bounds.y)
|
||||
{
|
||||
this.y = this.game.world.bounds.y;
|
||||
this.velocity.y *= -this.bounce.y;
|
||||
}
|
||||
else if (this.bottom > this.game.world.bounds.bottom)
|
||||
{
|
||||
this.y = this.game.world.bounds.bottom - this.height;
|
||||
this.velocity.y *= -this.bounce.y;
|
||||
}
|
||||
if (this.y < this.game.world.bounds.y)
|
||||
{
|
||||
this.y = this.game.world.bounds.y;
|
||||
this.velocity.y *= -this.bounce.y;
|
||||
}
|
||||
else if (this.bottom > this.game.world.bounds.bottom)
|
||||
{
|
||||
this.y = this.game.world.bounds.bottom - this.height;
|
||||
this.velocity.y *= -this.bounce.y;
|
||||
}
|
||||
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
* You can modify the size of the physics Body to be any dimension you need.
|
||||
@@ -485,46 +485,46 @@ Phaser.Physics.Arcade.Body.prototype = {
|
||||
* @param {number} offsetX - The X offset of the Body from the Sprite position.
|
||||
* @param {number} offsetY - The Y offset of the Body from the Sprite position.
|
||||
*/
|
||||
setSize: function (width, height, offsetX, offsetY) {
|
||||
setSize: function (width, height, offsetX, offsetY) {
|
||||
|
||||
offsetX = offsetX || this.offset.x;
|
||||
offsetY = offsetY || this.offset.y;
|
||||
offsetX = offsetX || this.offset.x;
|
||||
offsetY = offsetY || this.offset.y;
|
||||
|
||||
this.sourceWidth = width;
|
||||
this.sourceHeight = height;
|
||||
this.width = this.sourceWidth * this._sx;
|
||||
this.height = this.sourceHeight * this._sy;
|
||||
this.halfWidth = Math.floor(this.width / 2);
|
||||
this.halfHeight = Math.floor(this.height / 2);
|
||||
this.offset.setTo(offsetX, offsetY);
|
||||
this.sourceWidth = width;
|
||||
this.sourceHeight = height;
|
||||
this.width = this.sourceWidth * this._sx;
|
||||
this.height = this.sourceHeight * this._sy;
|
||||
this.halfWidth = Math.floor(this.width / 2);
|
||||
this.halfHeight = Math.floor(this.height / 2);
|
||||
this.offset.setTo(offsetX, offsetY);
|
||||
|
||||
this.center.setTo(this.x + this.halfWidth, this.y + this.halfHeight);
|
||||
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
* Resets all Body values (velocity, acceleration, rotation, etc)
|
||||
*
|
||||
* @method Phaser.Physics.Arcade#reset
|
||||
*/
|
||||
reset: function () {
|
||||
reset: function () {
|
||||
|
||||
this.velocity.setTo(0, 0);
|
||||
this.acceleration.setTo(0, 0);
|
||||
this.velocity.setTo(0, 0);
|
||||
this.acceleration.setTo(0, 0);
|
||||
|
||||
this.angularVelocity = 0;
|
||||
this.angularAcceleration = 0;
|
||||
this.angularVelocity = 0;
|
||||
this.angularAcceleration = 0;
|
||||
this.preX = (this.sprite.world.x - (this.sprite.anchor.x * this.width)) + this.offset.x;
|
||||
this.preY = (this.sprite.world.y - (this.sprite.anchor.y * this.height)) + this.offset.y;
|
||||
this.preRotation = this.sprite.angle;
|
||||
this.preRotation = this.sprite.angle;
|
||||
|
||||
this.x = this.preX;
|
||||
this.y = this.preY;
|
||||
this.rotation = this.preRotation;
|
||||
this.x = this.preX;
|
||||
this.y = this.preY;
|
||||
this.rotation = this.preRotation;
|
||||
|
||||
this.center.setTo(this.x + this.halfWidth, this.y + this.halfHeight);
|
||||
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the absolute delta x value.
|
||||
@@ -591,7 +591,7 @@ Object.defineProperty(Phaser.Physics.Arcade.Body.prototype, "bottom", {
|
||||
* The sum of the y and height properties. Changing the bottom property of a Rectangle object has no effect on the x, y and width properties, but does change the height property.
|
||||
* @method bottom
|
||||
* @param {number} value
|
||||
*/
|
||||
*/
|
||||
set: function (value) {
|
||||
|
||||
if (value <= this.y)
|
||||
@@ -618,7 +618,7 @@ Object.defineProperty(Phaser.Physics.Arcade.Body.prototype, "right", {
|
||||
* However it does affect the width property.
|
||||
* @method right
|
||||
* @return {number}
|
||||
*/
|
||||
*/
|
||||
get: function () {
|
||||
return this.x + this.width;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user