Commit before tidying up redundant files

This commit is contained in:
Richard Davey
2013-05-31 15:13:03 +01:00
parent 23ec3816db
commit fe372af453
16 changed files with 2277 additions and 1716 deletions
+3 -3
View File
@@ -639,9 +639,9 @@ module Phaser {
* @param context The context in which the callbacks will be called
* @returns {boolean} true if the objects overlap, otherwise false.
*/
//public collide(objectOrGroup1 = null, objectOrGroup2 = null, notifyCallback = null, context? = this.callbackContext): bool {
// return this.collision.overlap(objectOrGroup1, objectOrGroup2, notifyCallback, Collision.separate, context);
//}
public collide(objectOrGroup1 = null, objectOrGroup2 = null, notifyCallback = null, context? = this.callbackContext): bool {
return this.world.physics.overlap(objectOrGroup1, objectOrGroup2, notifyCallback, this.world.physics.separate, context);
}
public get camera(): Camera {
return this.world.cameras.current;
+14 -2
View File
@@ -121,9 +121,21 @@
</Content>
<TypeScriptCompile Include="physics\IPhysicsShape.ts" />
<TypeScriptCompile Include="physics\Circle.ts" />
<TypeScriptCompile Include="physics\Body.ts" />
<Content Include="physics\Body.js">
<DependentUpon>Body.ts</DependentUpon>
</Content>
<Content Include="physics\Circle.js">
<DependentUpon>Circle.ts</DependentUpon>
</Content>
<TypeScriptCompile Include="physics\IPhysicsBody.ts" />
<TypeScriptCompile Include="physics\Fixture.ts" />
<Content Include="physics\Fixture.js">
<DependentUpon>Fixture.ts</DependentUpon>
</Content>
<Content Include="physics\IPhysicsBody.js">
<DependentUpon>IPhysicsBody.ts</DependentUpon>
</Content>
<Content Include="physics\IPhysicsShape.js">
<DependentUpon>IPhysicsShape.ts</DependentUpon>
</Content>
@@ -215,7 +227,7 @@
<Content Include="math\LinkedList.js">
<DependentUpon>LinkedList.ts</DependentUpon>
</Content>
<Content Include="math\QuadTree.js">
<Content Include="physics\QuadTree.js">
<DependentUpon>QuadTree.ts</DependentUpon>
</Content>
<Content Include="math\RandomDataGenerator.js">
@@ -234,7 +246,7 @@
<TypeScriptCompile Include="system\StageScaleMode.ts" />
<TypeScriptCompile Include="system\RequestAnimationFrame.ts" />
<TypeScriptCompile Include="math\RandomDataGenerator.ts" />
<TypeScriptCompile Include="math\QuadTree.ts" />
<TypeScriptCompile Include="physics\QuadTree.ts" />
<TypeScriptCompile Include="math\LinkedList.ts" />
<TypeScriptCompile Include="system\Device.ts" />
<TypeScriptCompile Include="cameras\Camera.ts" />
+5
View File
@@ -24,6 +24,11 @@ module Phaser {
static GEOM_LINE: number = 3;
static GEOM_POLYGON: number = 4;
static BODY_DISABLED: number = 0;
static BODY_DYNAMIC: number = 1;
static BODY_STATIC: number = 2;
static BODY_KINEMATIC: number = 3;
/**
* Flag used to allow GameObjects to collide on their left side
* @type {number}
+1 -7
View File
@@ -37,8 +37,6 @@ module Phaser {
this.physics = new Physics.PhysicsManager(this._game, width, height);
this.worldDivisions = 6;
}
/**
@@ -70,17 +68,13 @@ module Phaser {
*/
public physics: Physics.PhysicsManager;
/**
* @type {number}
*/
public worldDivisions: number;
/**
* This is called automatically every frame, and is where main logic happens.
*/
public update() {
this.physics.update();
//this.physics.update();
this.group.update();
this.cameras.update();
+5 -2
View File
@@ -4,6 +4,7 @@
/// <reference path="../../physics/AABB.ts" />
/// <reference path="../../physics/Circle.ts" />
/// <reference path="../../physics/IPhysicsShape.ts" />
/// <reference path="../../physics/IPhysicsBody.ts" />
/**
* Phaser - Components - Physics
@@ -11,7 +12,7 @@
module Phaser.Components {
export class Physics {
export class Physics implements Phaser.Physics.IPhysicsBody {
constructor(parent: Sprite) {
@@ -50,7 +51,6 @@ module Phaser.Components {
* @type {boolean}
*/
public moves: bool = true;
public mass: number = 1;
public gravity: Vec2;
public drag: Vec2;
@@ -62,9 +62,11 @@ module Phaser.Components {
public touching: number;
public allowCollisions: number;
public wasTouching: number;
public mass: number = 1;
public setCircle(diameter: number) {
// Here is the stuff I want to remove
this.game.world.physics.remove(this.shape);
this.shape = this.game.world.physics.add(new Phaser.Physics.Circle(this.game, this._sprite, this._sprite.x, this._sprite.y, diameter));
this._sprite.physics.shape.physics = this;
@@ -76,6 +78,7 @@ module Phaser.Components {
*/
public update() {
// if this is all it does maybe move elsewhere? Sprite postUpdate?
if (this.moves && this.shape)
{
this._sprite.x = (this.shape.position.x - this.shape.bounds.halfWidth) - this.shape.offset.x;
+2 -2
View File
@@ -153,7 +153,7 @@ module Phaser {
* Calls update on all members of this Group who have a status of active=true and exists=true
* You can also call Object.update directly, which will bypass the active/exists check.
*/
public update(forceUpdate?: bool = false) {
public update() {
this._i = 0;
@@ -164,7 +164,7 @@ module Phaser {
if (this._member != null && this._member.exists && this._member.active)
{
this._member.preUpdate();
this._member.update(forceUpdate);
this._member.update();
this._member.postUpdate();
}
}
+4 -15
View File
@@ -62,11 +62,12 @@ module Phaser {
*
* @param x {number} X position of the new sprite.
* @param y {number} Y position of the new sprite.
* @param key {string} Optional, key for the sprite sheet you want it to use.
* @param [key] {string} The image key as defined in the Game.Cache to use as the texture for this sprite
* @param [bodyType] {number} The physics body type of the object (defaults to BODY_DISABLED)
* @returns {Sprite} The newly created sprite object.
*/
public sprite(x: number, y: number, key?: string = ''): Sprite {
return <Sprite> this._world.group.add(new Sprite(this._game, x, y, key));
public sprite(x: number, y: number, key?: string = '', bodyType?: number = Phaser.Types.BODY_DISABLED): Sprite {
return <Sprite> this._world.group.add(new Sprite(this._game, x, y, key, bodyType));
}
/**
@@ -90,18 +91,6 @@ module Phaser {
return <Group> this._world.group.add(new Group(this._game, maxSize));
}
/**
* Create a new Sprite with specific position and sprite sheet key.
*
* @param x {number} X position of the new sprite.
* @param y {number} Y position of the new sprite.
* @param key {string} Optional, key for the sprite sheet you want it to use.
* @returns {Sprite} The newly created sprite object.
* WILL NEED TO TRACK A SPRITE
*/
public physicsAABB(x: number, y: number, width: number, height: number): Physics.AABB {
return <Physics.AABB> this._world.physics.add(new Physics.AABB(this._game, null, x, y, width, height));
}
/**
* Create a new Particle.
+21 -29
View File
@@ -4,6 +4,7 @@
/// <reference path="../components/animation/AnimationManager.ts" />
/// <reference path="../components/sprite/Texture.ts" />
/// <reference path="../components/sprite/Physics.ts" />
/// <reference path="../physics/Body.ts" />
/**
* Phaser - Sprite
@@ -21,10 +22,10 @@ module Phaser {
* @param [x] {number} the initial x position of the sprite.
* @param [y] {number} the initial y position of the sprite.
* @param [key] {string} Key of the graphic you want to load for this sprite.
* @param [width] {number} The width of the object.
* @param [height] {number} The height of the object.
* @param [bodyType] {number} The physics body type of the object (defaults to BODY_DISABLED)
*/
constructor(game: Game, x?: number = 0, y?: number = 0, key?: string = null, width?: number = 16, height?: number = 16) {
//constructor(game: Game, x?: number = 0, y?: number = 0, key?: string = null, width?: number = 16, height?: number = 16) {
constructor(game: Game, x?: number = 0, y?: number = 0, key?: string = null, bodyType?: number = Phaser.Types.BODY_DISABLED) {
this.game = game;
this.type = Phaser.Types.SPRITE;
@@ -35,7 +36,8 @@ module Phaser {
this.visible = true;
this.alive = true;
this.frameBounds = new Rectangle(x, y, width, height);
// We give it a default size of 16x16 but when the texture loads (if given) it will reset this
this.frameBounds = new Rectangle(x, y, 16, 16);
this.scrollFactor = new Phaser.Vec2(1, 1);
this.x = x;
@@ -50,17 +52,11 @@ module Phaser {
this.scale = new Phaser.Vec2(1, 1);
this.skew = new Phaser.Vec2(0, 0);
this.physics = new Phaser.Components.Physics(this);
this.physics.shape.physics = this.physics;
// If a texture has been given the body will be set to that size, otherwise 16x16
this.body = new Phaser.Physics.Body(this, bodyType);
}
/**
* Rotation angle of this object.
* @type {number}
*/
private _rotation: number = 0;
/**
* Reference to the main game object
*/
@@ -97,9 +93,9 @@ module Phaser {
public alive: bool;
/**
* Sprite physics.
* Sprite physics body.
*/
public physics: Phaser.Components.Physics;
public body: Phaser.Physics.Body;
/**
* The texture used to render the Sprite.
@@ -160,26 +156,26 @@ module Phaser {
public z: number = 0;
/**
* This value is added to the rotation of the Sprite.
* This value is added to the angle of the Sprite.
* For example if you had a sprite graphic drawn facing straight up then you could set
* rotationOffset to 90 and it would correspond correctly with Phasers right-handed coordinate system.
* angleOffset to 90 and it would correspond correctly with Phasers right-handed coordinate system.
* @type {number}
*/
public rotationOffset: number = 0;
public angleOffset: number = 0;
/**
* The rotation of the sprite in degrees. Phaser uses a right-handed coordinate system, where 0 points to the right.
* The angle of the sprite in degrees. Phaser uses a right-handed coordinate system, where 0 points to the right.
*/
public get rotation(): number {
return this._rotation;
public get angle(): number {
return this.body.angle;
}
/**
* Set the rotation of the sprite in degrees. Phaser uses a right-handed coordinate system, where 0 points to the right.
* Set the angle of the sprite in degrees. Phaser uses a right-handed coordinate system, where 0 points to the right.
* The value is automatically wrapped to be between 0 and 360.
*/
public set rotation(value: number) {
this._rotation = this.game.math.wrap(value, 360, 0);
public set angle(value: number) {
this.body.angle = this.game.math.wrap(value, 360, 0);
}
/**
@@ -234,7 +230,7 @@ module Phaser {
this.frameBounds.x = this.x;
this.frameBounds.y = this.y;
if (this.modified == false && (!this.scale.equals(1) || !this.skew.equals(0) || this.rotation != 0 || this.rotationOffset != 0 || this.texture.flippedX || this.texture.flippedY))
if (this.modified == false && (!this.scale.equals(1) || !this.skew.equals(0) || this.angle != 0 || this.angleOffset != 0 || this.texture.flippedX || this.texture.flippedY))
{
this.modified = true;
}
@@ -253,7 +249,7 @@ module Phaser {
public postUpdate() {
this.animations.update();
this.physics.update();
this.body.postUpdate();
/*
if (this.worldBounds != null)
@@ -287,15 +283,11 @@ module Phaser {
}
}
this.collisionMask.update();
if (this.inputEnabled)
{
this.updateInput();
}
this.wasTouching = this.touching;
this.touching = Collision.NONE;
*/
if (this.modified == true && this.scale.equals(1) && this.skew.equals(0) && this.rotation == 0 && this.rotationOffset == 0 && this.texture.flippedX == false && this.texture.flippedY == false)
+285
View File
@@ -0,0 +1,285 @@
/// <reference path="../core/Vec2.ts" />
/// <reference path="../core/Point.ts" />
/// <reference path="../math/Vec2Utils.ts" />
/// <reference path="../physics/AABB.ts" />
/// <reference path="../physics/Circle.ts" />
/// <reference path="../physics/IPhysicsBody.ts" />
/**
* Phaser - Physics - Body
*/
module Phaser.Physics {
export class Body {
constructor(parent: Sprite, type: number) {
this.parent = parent;
this.game = parent.game;
this.type = type;
// Fixture properties
// Will extend into its own class at a later date - can move the fixture defs there and add shape support, but this will do for 1.0 release
this.bounds = new Rectangle(parent.x + Math.round(parent.width / 2), parent.y + Math.round(parent.height / 2), parent.width, parent.height);
this.bounce = Vec2Utils.clone(this.game.world.physics.bounce);
// Body properties
this.gravity = Vec2Utils.clone(this.game.world.physics.gravity);
this.velocity = new Vec2;
this.acceleration = new Vec2;
this.drag = Vec2Utils.clone(this.game.world.physics.drag);
this.maxVelocity = new Vec2(10000, 10000);
this.angle = 0;
this.angularVelocity = 0;
this.angularAcceleration = 0;
this.angularDrag = 0;
this.touching = Types.NONE;
this.wasTouching = Types.NONE;
this.allowCollisions = Types.ANY;
this.position = new Vec2(parent.x + this.bounds.halfWidth, parent.y + this.bounds.halfHeight);
this.oldPosition = new Vec2(parent.x + this.bounds.halfWidth, parent.y + this.bounds.halfHeight);
this.offset = new Vec2;
}
public game: Game;
public parent: Sprite;
/**
* The type of Body (disabled, dynamic, static or kinematic)
* Disabled = skips all physics operations / tests (default)
* Dynamic = gives and receives impacts
* Static = gives but doesn't receive impacts, cannot be moved by physics
* Kinematic = gives impacts, but never receives, can be moved by physics
* @type {number}
*/
public type: number;
public gravity: Vec2;
public bounce: Vec2;
public velocity: Vec2;
public acceleration: Vec2;
public drag: Vec2;
public maxVelocity: Vec2;
public angularVelocity: number = 0;
public angularAcceleration: number = 0;
public angularDrag: number = 0;
public maxAngular: number = 10000;
/**
* Angle of rotation of this body.
* @type {number}
*/
public angle: number;
/**
* Orientation of the object.
* @type {number}
*/
public facing: number;
public touching: number;
public allowCollisions: number;
public wasTouching: number;
public mass: number = 1;
public position: Vec2;
public oldPosition: Vec2;
public offset: Vec2;
public bounds: Rectangle;
public preUpdate() {
this.oldPosition.copyFrom(this.position);
this.bounds.x = this.position.x - this.bounds.halfWidth;
this.bounds.y = this.position.y - this.bounds.halfHeight;
if (this.parent.scale.equals(1) == false)
{
}
}
// Shall we do this? Or just update the values directly in the separate functions? But then the bounds will be out of sync - as long as
// the bounds are updated and used in calculations then we can do one final sprite movement here I guess?
public postUpdate() {
// if this is all it does maybe move elsewhere? Sprite postUpdate?
if (this.type !== Phaser.Types.BODY_DISABLED)
{
this.game.world.physics.updateMotion(this);
this.parent.x = (this.position.x - this.bounds.halfWidth) - this.offset.x;
this.parent.y = (this.position.y - this.bounds.halfHeight) - this.offset.y;
this.wasTouching = this.touching;
this.touching = Phaser.Types.NONE;
}
}
public get hullWidth(): number {
if (this.deltaX > 0)
{
return this.bounds.width + this.deltaX;
}
else
{
return this.bounds.width - this.deltaX;
}
}
public get hullHeight(): number {
if (this.deltaY > 0)
{
return this.bounds.height + this.deltaY;
}
else
{
return this.bounds.height - this.deltaY;
}
}
public get hullX(): number {
if (this.position.x < this.oldPosition.x)
{
return this.position.x;
}
else
{
return this.oldPosition.x;
}
}
public get hullY(): number {
if (this.position.y < this.oldPosition.y)
{
return this.position.y;
}
else
{
return this.oldPosition.y;
}
}
public get deltaXAbs(): number {
return (this.deltaX > 0 ? this.deltaX : -this.deltaX);
}
public get deltaYAbs(): number {
return (this.deltaY > 0 ? this.deltaY : -this.deltaY);
}
public get deltaX(): number {
return this.position.x - this.oldPosition.x;
}
public get deltaY(): number {
return this.position.y - this.oldPosition.y;
}
// MOVE THESE TO A UTIL
public render(context:CanvasRenderingContext2D) {
context.beginPath();
context.strokeStyle = 'rgb(0,255,0)';
context.strokeRect(this.position.x - this.bounds.halfWidth, this.position.y - this.bounds.halfHeight, this.bounds.width, this.bounds.height);
context.stroke();
context.closePath();
// center point
context.fillStyle = 'rgb(0,255,0)';
context.fillRect(this.position.x, this.position.y, 2, 2);
if (this.touching & Phaser.Types.LEFT)
{
context.beginPath();
context.strokeStyle = 'rgb(255,0,0)';
context.moveTo(this.position.x - this.bounds.halfWidth, this.position.y - this.bounds.halfHeight);
context.lineTo(this.position.x - this.bounds.halfWidth, this.position.y + this.bounds.halfHeight);
context.stroke();
context.closePath();
}
if (this.touching & Phaser.Types.RIGHT)
{
context.beginPath();
context.strokeStyle = 'rgb(255,0,0)';
context.moveTo(this.position.x + this.bounds.halfWidth, this.position.y - this.bounds.halfHeight);
context.lineTo(this.position.x + this.bounds.halfWidth, this.position.y + this.bounds.halfHeight);
context.stroke();
context.closePath();
}
if (this.touching & Phaser.Types.UP)
{
context.beginPath();
context.strokeStyle = 'rgb(255,0,0)';
context.moveTo(this.position.x - this.bounds.halfWidth, this.position.y - this.bounds.halfHeight);
context.lineTo(this.position.x + this.bounds.halfWidth, this.position.y - this.bounds.halfHeight);
context.stroke();
context.closePath();
}
if (this.touching & Phaser.Types.DOWN)
{
context.beginPath();
context.strokeStyle = 'rgb(255,0,0)';
context.moveTo(this.position.x - this.bounds.halfWidth, this.position.y + this.bounds.halfHeight);
context.lineTo(this.position.x + this.bounds.halfWidth, this.position.y + this.bounds.halfHeight);
context.stroke();
context.closePath();
}
}
/**
* Render debug infos. (including name, bounds info, position and some other properties)
* @param x {number} X position of the debug info to be rendered.
* @param y {number} Y position of the debug info to be rendered.
* @param [color] {number} color of the debug info to be rendered. (format is css color string)
*/
public renderDebugInfo(x: number, y: number, color?: string = 'rgb(255,255,255)') {
this.parent.texture.context.fillStyle = color;
this.parent.texture.context.fillText('Sprite: (' + this.parent.frameBounds.width + ' x ' + this.parent.frameBounds.height + ')', x, y);
//this.parent.texture.context.fillText('x: ' + this._parent.frameBounds.x.toFixed(1) + ' y: ' + this._parent.frameBounds.y.toFixed(1) + ' rotation: ' + this._parent.rotation.toFixed(1), x, y + 14);
this.parent.texture.context.fillText('x: ' + this.shape.bounds.x.toFixed(1) + ' y: ' + this.shape.bounds.y.toFixed(1) + ' rotation: ' + this._parent.rotation.toFixed(1), x, y + 14);
this.parent.texture.context.fillText('vx: ' + this.velocity.x.toFixed(1) + ' vy: ' + this.velocity.y.toFixed(1), x, y + 28);
this.parent.texture.context.fillText('ax: ' + this.acceleration.x.toFixed(1) + ' ay: ' + this.acceleration.y.toFixed(1), x, y + 42);
}
}
}
+31
View File
@@ -0,0 +1,31 @@
/// <reference path="../core/Vec2.ts" />
/// <reference path="../core/Point.ts" />
/// <reference path="../math/Vec2Utils.ts" />
/// <reference path="../physics/AABB.ts" />
/// <reference path="../physics/Circle.ts" />
/// <reference path="../physics/IPhysicsBody.ts" />
/**
* Phaser - Physics - Fixture
*/
module Phaser.Physics {
export class Fixture {
constructor(parent: Sprite, type: number) {
this.parent = parent;
// these are shape properties really
this.bounce = Vec2Utils.clone(this.game.world.physics.bounce);
this.friction = Vec2Utils.clone(this.game.world.physics.friction);
}
public game: Game;
public parent: Sprite;
}
}
+40
View File
@@ -0,0 +1,40 @@
/// <reference path="../Game.ts" />
/// <reference path="../core/Rectangle.ts" />
/// <reference path="PhysicsManager.ts" />
/**
* Phaser - Physics - IPhysicsShape
*/
module Phaser.Physics {
export interface IPhysicsBody {
//game: Game;
//world: PhysicsManager;
//sprite: Sprite;
//physics: Phaser.Components.Physics;
//position: Vec2;
//oldPosition: Vec2;
//offset: Vec2;
//bounds: Rectangle;
//setSize(width: number, height: number);
//preUpdate();
//update();
//render(context:CanvasRenderingContext2D);
//hullX;
//hullY;
//hullWidth;
//hullHeight;
//deltaX;
//deltaY;
//deltaXAbs;
//deltaYAbs;
}
}
+175 -208
View File
@@ -1,7 +1,8 @@
/// <reference path="../Game.ts" />
/// <reference path="IPhysicsShape.ts" />
/// <reference path="../utils/RectangleUtils.ts" />
/// <reference path="../utils/CircleUtils.ts" />
/// <reference path="Body.ts" />
/// <reference path="QuadTree.ts" />
/**
* Phaser - PhysicsManager
@@ -21,14 +22,14 @@ module Phaser.Physics {
this.gravity = new Vec2;
this.drag = new Vec2;
this.bounce = new Vec2;
this.friction = new Vec2;
this.angularDrag = 0;
this.bounds = new Rectangle(0, 0, width, height);
this._distance = new Vec2;
this._tangent = new Vec2;
this._objects = [];
this.members = new Group(game);
}
@@ -37,7 +38,10 @@ module Phaser.Physics {
*/
public game: Game;
private _objects: IPhysicsShape[];
/**
* Physics object pool
*/
public members: Group;
// Temp calculation vars
private _drag: number;
@@ -46,15 +50,38 @@ module Phaser.Physics {
private _length: number = 0;
private _distance: Vec2;
private _tangent: Vec2;
private _separatedX: bool;
private _separatedY: bool;
private _overlap: number;
private _maxOverlap: number;
private _obj1Velocity: number;
private _obj2Velocity: number;
private _obj1NewVelocity: number;
private _obj2NewVelocity: number;
private _average: number;
private _quadTree: QuadTree;
private _quadTreeResult: bool;
public bounds: Rectangle;
public gravity: Vec2;
public drag: Vec2;
public bounce: Vec2;
public friction: Vec2;
public angularDrag: number;
static OVERLAP_BIAS: number = 4;
/**
* @type {number}
*/
public worldDivisions: number = 6;
// Add some sanity checks here + remove method, etc
/*
public add(shape: IPhysicsShape): IPhysicsShape {
this._objects.push(shape);
@@ -115,32 +142,31 @@ module Phaser.Physics {
}
}
*/
private updateMotion(shape: IPhysicsShape) {
public updateMotion(body: Phaser.Physics.Body) {
if (shape.physics.moves == false)
if (body.type == Types.BODY_DISABLED)
{
return;
}
/*
velocityDelta = (this._game.motion.computeVelocity(this.angularVelocity, this.angularAcceleration, this.angularDrag, this.maxAngular) - this.angularVelocity) / 2;
this.angularVelocity += velocityDelta;
this._angle += this.angularVelocity * this._game.time.elapsed;
this.angularVelocity += velocityDelta;
*/
this._velocityDelta = (this.computeVelocity(body.angularVelocity, body.angularAcceleration, body.angularDrag, body.maxAngular) - body.angularVelocity) / 2;
body.angularVelocity += this._velocityDelta;
body.angle += body.angularVelocity * this.game.time.elapsed;
body.angularVelocity += this._velocityDelta;
this._velocityDelta = (this.computeVelocity(shape.physics.velocity.x, shape.physics.gravity.x, shape.physics.acceleration.x, shape.physics.drag.x) - shape.physics.velocity.x) / 2;
shape.physics.velocity.x += this._velocityDelta;
this._delta = shape.physics.velocity.x * this.game.time.elapsed;
shape.physics.velocity.x += this._velocityDelta;
shape.position.x += this._delta;
this._velocityDelta = (this.computeVelocity(body.velocity.x, body.gravity.x, body.acceleration.x, body.drag.x) - body.velocity.x) / 2;
body.velocity.x += this._velocityDelta;
this._delta = body.velocity.x * this.game.time.elapsed;
body.velocity.x += this._velocityDelta;
body.position.x += this._delta;
this._velocityDelta = (this.computeVelocity(shape.physics.velocity.y, shape.physics.gravity.y, shape.physics.acceleration.y, shape.physics.drag.y) - shape.physics.velocity.y) / 2;
shape.physics.velocity.y += this._velocityDelta;
this._delta = shape.physics.velocity.y * this.game.time.elapsed;
shape.physics.velocity.y += this._velocityDelta;
shape.position.y += this._delta;
this._velocityDelta = (this.computeVelocity(body.velocity.y, body.gravity.y, body.acceleration.y, body.drag.y) - body.velocity.y) / 2;
body.velocity.y += this._velocityDelta;
this._delta = body.velocity.y * this.game.time.elapsed;
body.velocity.y += this._velocityDelta;
body.position.y += this._delta;
}
@@ -265,17 +291,17 @@ module Phaser.Physics {
}
/**
* The core Collision separation function used by Collision.overlap.
* @param object1 The first GameObject to separate
* @param object2 The second GameObject to separate
* @returns {boolean} Returns true if the objects were separated, otherwise false.
* The core Collision separation method.
* @param body1 The first Physics.Body to separate
* @param body2 The second Physics.Body to separate
* @returns {boolean} Returns true if the bodies were separated, otherwise false.
*/
public NEWseparate(object1, object2): bool {
public separate(body1: Body, body2: Body): bool {
var separatedX: bool = this.separateSpriteToSpriteX(object1, object2);
var separatedY: bool = this.separateSpriteToSpriteY(object1, object2);
this._separatedX = this.separateBodyX(body1, body2);
this._separatedY = this.separateBodyY(body1, body2);
return separatedX || separatedY;
return this._separatedX || this._separatedY;
}
@@ -300,98 +326,95 @@ module Phaser.Physics {
* @param object2 The second GameObject to separate
* @returns {boolean} Whether the objects in fact touched and were separated along the X axis.
*/
public separateSpriteToSpriteX(object1:Sprite, object2:Sprite): bool {
public separateBodyX(body1: Body, body2: Body): bool {
// Can't separate two immovable objects
if (object1.physics.immovable && object2.physics.immovable)
// Can't separate two disabled or static objects
if ((body1.type == Types.BODY_DISABLED || body1.type == Types.BODY_STATIC) && (body2.type == Types.BODY_DISABLED || body2.type == Types.BODY_STATIC))
{
return false;
}
// First, get the two object deltas
var overlap: number = 0;
this._overlap = 0;
if (object1.physics.shape.deltaX != object2.physics.shape.deltaX)
if (body1.deltaX != body2.deltaX)
{
//var intersects: bool = false;
//if (object1.physics.shape['radius'])
//{
// intersects = CircleUtils.intersectsRectangle(object1.physics.shape, object2.physics.shape.bounds)
//}
//else
//{
// intersects = RectangleUtils.intersects(object1.physics.shape.bounds, object2.physics.shape.bounds)
//}
if (RectangleUtils.intersects(object1.physics.shape.bounds, object2.physics.shape.bounds))
if (RectangleUtils.intersects(body1.bounds, body2.bounds))
{
//var maxOverlap: number = object1.physics.shape.deltaXAbs + object2.physics.shape.deltaXAbs + Collision.OVERLAP_BIAS;
var maxOverlap: number = object1.physics.shape.deltaXAbs + object2.physics.shape.deltaXAbs + 4;
this._maxOverlap = body1.deltaXAbs + body2.deltaXAbs + PhysicsManager.OVERLAP_BIAS;
// If they did overlap (and can), figure out by how much and flip the corresponding flags
if (object1.physics.shape.deltaX > object2.physics.shape.deltaX)
if (body1.deltaX > body2.deltaX)
{
overlap = object1.physics.shape.bounds.right - object2.physics.shape.bounds.x;
this._overlap = body1.bounds.right - body2.bounds.x;
if ((overlap > maxOverlap) || !(object1.physics.allowCollisions & Phaser.Types.RIGHT) || !(object2.physics.allowCollisions & Phaser.Types.LEFT))
if ((this._overlap > this._maxOverlap) || !(body1.allowCollisions & Types.RIGHT) || !(body2.allowCollisions & Types.LEFT))
{
overlap = 0;
this._overlap = 0;
}
else
{
object1.physics.touching |= Phaser.Types.RIGHT;
object2.physics.touching |= Phaser.Types.LEFT;
body1.touching |= Types.RIGHT;
body2.touching |= Types.LEFT;
}
}
else if (object1.physics.shape.deltaX < object2.physics.shape.deltaX)
else if (body1.deltaX < body2.deltaX)
{
overlap = object1.physics.shape.bounds.x - object2.physics.shape.bounds.width - object2.physics.shape.bounds.x;
this._overlap = body1.bounds.x - body2.bounds.width - body2.bounds.x;
if ((-overlap > maxOverlap) || !(object1.physics.allowCollisions & Phaser.Types.LEFT) || !(object2.physics.allowCollisions & Phaser.Types.RIGHT))
if ((-this._overlap > this._maxOverlap) || !(body1.allowCollisions & Types.LEFT) || !(body2.allowCollisions & Types.RIGHT))
{
overlap = 0;
this._overlap = 0;
}
else
{
object1.physics.touching |= Phaser.Types.LEFT;
object2.physics.touching |= Phaser.Types.RIGHT;
body1.touching |= Types.LEFT;
body2.touching |= Types.RIGHT;
}
}
}
}
// Then adjust their positions and velocities accordingly (if there was any overlap)
if (overlap != 0)
if (this._overlap != 0)
{
var obj1Velocity: number = object1.physics.velocity.x;
var obj2Velocity: number = object2.physics.velocity.x;
this._obj1Velocity = body1.velocity.x;
this._obj2Velocity = body2.velocity.x;
if (!object1.physics.immovable && !object2.physics.immovable)
{
overlap *= 0.5;
object1.physics.shape.position.x = object1.physics.shape.position.x - overlap;
object2.physics.shape.position.x += overlap;
/**
* Dynamic = gives and receives impacts
* Static = gives but doesn't receive impacts, cannot be moved by physics
* Kinematic = gives impacts, but never receives, can be moved by physics
*/
var obj1NewVelocity: number = Math.sqrt((obj2Velocity * obj2Velocity * object2.physics.mass) / object1.physics.mass) * ((obj2Velocity > 0) ? 1 : -1);
var obj2NewVelocity: number = Math.sqrt((obj1Velocity * obj1Velocity * object1.physics.mass) / object2.physics.mass) * ((obj1Velocity > 0) ? 1 : -1);
var average: number = (obj1NewVelocity + obj2NewVelocity) * 0.5;
obj1NewVelocity -= average;
obj2NewVelocity -= average;
object1.physics.velocity.x = average + obj1NewVelocity * object1.physics.bounce.x;
object2.physics.velocity.x = average + obj2NewVelocity * object2.physics.bounce.x;
}
else if (!object1.physics.immovable)
// 2 dynamic bodies will exchange velocities
if (body1.type == Types.BODY_DYNAMIC && body2.type == Types.BODY_DYNAMIC)
{
overlap *= 2;
object1.physics.shape.position.x -= overlap;
object1.physics.velocity.x = obj2Velocity - obj1Velocity * object1.physics.bounce.x;
this._overlap *= 0.5;
body1.position.x = body1.position.x - this._overlap;
body2.position.x += this._overlap;
this._obj1NewVelocity = Math.sqrt((this._obj2Velocity * this._obj2Velocity * body2.mass) / body1.mass) * ((this._obj2Velocity > 0) ? 1 : -1);
this._obj2NewVelocity = Math.sqrt((this._obj1Velocity * this._obj1Velocity * body1.mass) / body2.mass) * ((this._obj1Velocity > 0) ? 1 : -1);
this._average = (this._obj1NewVelocity + this._obj2NewVelocity) * 0.5;
this._obj1NewVelocity -= this._average;
this._obj2NewVelocity -= this._average;
body1.velocity.x = this._average + this._obj1NewVelocity * body1.bounce.x;
body2.velocity.x = this._average + this._obj2NewVelocity * body2.bounce.x;
}
else if (!object2.physics.immovable)
else if (body2.type != Types.BODY_DYNAMIC)
{
overlap *= 2;
object2.physics.shape.position.x += overlap;
object2.physics.velocity.x = obj1Velocity - obj2Velocity * object2.physics.bounce.x;
// Body 2 is Static or Kinematic
this._overlap *= 2;
body1.position.x -= this._overlap;
body1.velocity.x = this._obj2Velocity - this._obj1Velocity * body1.bounce.x;
}
else if (body1.type != Types.BODY_DYNAMIC)
{
// Body 1 is Static or Kinematic
this._overlap *= 2;
body2.position.x += this._overlap;
body2.velocity.x = this._obj1Velocity - this._obj2Velocity * body2.bounce.x;
}
return true;
@@ -409,96 +432,104 @@ module Phaser.Physics {
* @param object2 The second GameObject to separate
* @returns {boolean} Whether the objects in fact touched and were separated along the Y axis.
*/
public separateSpriteToSpriteY(object1:Sprite, object2:Sprite): bool {
public separateBodyY(body1: Body, body2: Body): bool {
// Can't separate two immovable objects
if (object1.physics.immovable && object2.physics.immovable) {
if ((body1.type == Types.BODY_DISABLED || body1.type == Types.BODY_STATIC) && (body2.type == Types.BODY_DISABLED || body2.type == Types.BODY_STATIC))
{
return false;
}
// First, get the two object deltas
var overlap: number = 0;
this._overlap = 0;
if (object1.physics.shape.deltaY != object2.physics.shape.deltaY)
if (body1.deltaY != body2.deltaY)
{
if (RectangleUtils.intersects(object1.physics.shape.bounds, object2.physics.shape.bounds))
if (RectangleUtils.intersects(body1.bounds, body2.bounds))
{
// This is the only place to use the DeltaAbs values
//var maxOverlap: number = object1.physics.shape.deltaYAbs + object2.physics.shape.deltaYAbs + Phaser.Types.OVERLAP_BIAS;
var maxOverlap: number = object1.physics.shape.deltaYAbs + object2.physics.shape.deltaYAbs + 4;
this._maxOverlap = body1.deltaYAbs + body2.deltaYAbs + PhysicsManager.OVERLAP_BIAS;
// If they did overlap (and can), figure out by how much and flip the corresponding flags
if (object1.physics.shape.deltaY > object2.physics.shape.deltaY)
if (body1.deltaY > body2.deltaY)
{
overlap = object1.physics.shape.bounds.bottom - object2.physics.shape.bounds.y;
this._overlap = body1.bounds.bottom - body2.bounds.y;
if ((overlap > maxOverlap) || !(object1.physics.allowCollisions & Phaser.Types.DOWN) || !(object2.physics.allowCollisions & Phaser.Types.UP))
if ((this._overlap > this._maxOverlap) || !(body1.allowCollisions & Types.DOWN) || !(body2.allowCollisions & Types.UP))
{
overlap = 0;
this._overlap = 0;
}
else
{
object1.physics.touching |= Phaser.Types.DOWN;
object2.physics.touching |= Phaser.Types.UP;
body1.touching |= Types.DOWN;
body2.touching |= Types.UP;
}
}
else if (object1.physics.shape.deltaY < object2.physics.shape.deltaY)
else if (body1.deltaY < body2.deltaY)
{
overlap = object1.physics.shape.bounds.y - object2.physics.shape.bounds.height - object2.physics.shape.bounds.y;
this._overlap = body1.bounds.y - body2.bounds.height - body2.bounds.y;
if ((-overlap > maxOverlap) || !(object1.physics.allowCollisions & Phaser.Types.UP) || !(object2.physics.allowCollisions & Phaser.Types.DOWN))
if ((-this._overlap > this._maxOverlap) || !(body1.allowCollisions & Types.UP) || !(body2.allowCollisions & Types.DOWN))
{
overlap = 0;
this._overlap = 0;
}
else
{
object1.physics.touching |= Phaser.Types.UP;
object2.physics.touching |= Phaser.Types.DOWN;
body1.touching |= Types.UP;
body2.touching |= Types.DOWN;
}
}
}
}
// Then adjust their positions and velocities accordingly (if there was any overlap)
if (overlap != 0)
if (this._overlap != 0)
{
var obj1Velocity: number = object1.physics.velocity.y;
var obj2Velocity: number = object2.physics.velocity.y;
this._obj1Velocity = body1.velocity.y;
this._obj2Velocity = body2.velocity.y;
if (!object1.physics.immovable && !object2.physics.immovable)
/**
* Dynamic = gives and receives impacts
* Static = gives but doesn't receive impacts, cannot be moved by physics
* Kinematic = gives impacts, but never receives, can be moved by physics
*/
if (body1.type == Types.BODY_DYNAMIC && body2.type == Types.BODY_DYNAMIC)
{
overlap *= 0.5;
object1.physics.shape.position.y = object1.physics.shape.position.y - overlap;
object2.physics.shape.position.y += overlap;
this._overlap *= 0.5;
body1.position.y = body1.position.y - this._overlap;
body2.position.y += this._overlap;
var obj1NewVelocity: number = Math.sqrt((obj2Velocity * obj2Velocity * object2.physics.mass) / object1.physics.mass) * ((obj2Velocity > 0) ? 1 : -1);
var obj2NewVelocity: number = Math.sqrt((obj1Velocity * obj1Velocity * object1.physics.mass) / object2.physics.mass) * ((obj1Velocity > 0) ? 1 : -1);
var average: number = (obj1NewVelocity + obj2NewVelocity) * 0.5;
obj1NewVelocity -= average;
obj2NewVelocity -= average;
object1.physics.velocity.y = average + obj1NewVelocity * object1.physics.bounce.y;
object2.physics.velocity.y = average + obj2NewVelocity * object2.physics.bounce.y;
this._obj1NewVelocity = Math.sqrt((this._obj2Velocity * this._obj2Velocity * body2.mass) / body1.mass) * ((this._obj2Velocity > 0) ? 1 : -1);
this._obj2NewVelocity = Math.sqrt((this._obj1Velocity * this._obj1Velocity * body1.mass) / body2.mass) * ((this._obj1Velocity > 0) ? 1 : -1);
var average: number = (this._obj1NewVelocity + this._obj2NewVelocity) * 0.5;
this._obj1NewVelocity -= average;
this._obj2NewVelocity -= average;
body1.velocity.y = average + this._obj1NewVelocity * body1.bounce.y;
body2.velocity.y = average + this._obj2NewVelocity * body2.bounce.y;
}
else if (!object1.physics.immovable)
else if (body2.type != Types.BODY_DYNAMIC)
{
overlap *= 2;
object1.physics.shape.position.y -= overlap;
object1.physics.velocity.y = obj2Velocity - obj1Velocity * object1.physics.bounce.y;
this._overlap *= 2;
body1.position.y -= this._overlap;
body1.velocity.y = this._obj2Velocity - this._obj1Velocity * body1.bounce.y;
// This is special case code that handles things like horizontal moving platforms you can ride
if (object2.active && object2.physics.moves && (object1.physics.shape.deltaY > object2.physics.shape.deltaY))
//if (body2.parent.active && body2.moves && (body1.deltaY > body2.deltaY))
if (body2.parent.active && (body1.deltaY > body2.deltaY))
{
object1.physics.shape.position.x += object2.physics.shape.position.x - object2.physics.shape.oldPosition.x;
body1.position.x += body2.position.x - body2.oldPosition.x;
}
}
else if (!object2.physics.immovable)
else if (body1.type != Types.BODY_DYNAMIC)
{
overlap *= 2;
object2.physics.shape.position.y += overlap;
object2.physics.velocity.y = obj1Velocity - obj2Velocity * object2.physics.bounce.y;
this._overlap *= 2;
body2.position.y += this._overlap;
body2.velocity.y = this._obj1Velocity - this._obj2Velocity * body2.bounce.y;
// This is special case code that handles things like horizontal moving platforms you can ride
if (object1.active && object1.physics.moves && (object1.physics.shape.deltaY < object2.physics.shape.deltaY))
//if (object1.active && body1.moves && (body1.deltaY < body2.deltaY))
if (body1.parent.active && (body1.deltaY < body2.deltaY))
{
object2.physics.shape.position.x += object1.physics.shape.position.x - object1.physics.shape.oldPosition.x;
body2.position.x += body1.position.x - body1.oldPosition.x;
}
}
@@ -517,7 +548,7 @@ module Phaser.Physics {
private separate(shapeA: IPhysicsShape, shapeB: IPhysicsShape, distance: Vec2, tangent: Vec2) {
private OLDseparate(shapeA: IPhysicsShape, shapeB: IPhysicsShape, distance: Vec2, tangent: Vec2) {
if (tangent.x == 1)
{
@@ -777,83 +808,21 @@ module Phaser.Physics {
}
private OLDseparate(shape:IPhysicsShape, distance: Vec2, tangent: Vec2) {
// collision edges
//shape.oH = tangent.x;
//shape.oV = tangent.y;
// Velocity (move to temp vars)
// was vx/vy
var velocity: Vec2 = Vec2Utils.subtract(shape.position, shape.oldPosition);
// was dp
var dot: number = Vec2Utils.dot(shape.physics.velocity, tangent);
// project velocity onto the collision normal
// was nx/ny
tangent.multiplyByScalar(dot);
// was tx/ty (tangent velocity?)
var tangentVelocity: Vec2 = Vec2Utils.subtract(velocity, tangent);
// only apply collision response forces if the object is travelling into, and not out of, the collision
if (dot < 0)
{
// Apply horizontal bounce
if (distance.x != 0)
{
if (shape.physics.bounce.x > 0)
{
shape.physics.velocity.x *= -(shape.physics.bounce.x);
}
else
{
shape.physics.velocity.x = 0;
}
}
// Apply vertical bounce
if (distance.y != 0)
{
if (shape.physics.bounce.y > 0)
{
shape.physics.velocity.y *= -(shape.physics.bounce.y);
}
else
{
shape.physics.velocity.y = 0;
}
}
}
else
{
// moving out of collision
}
// project object out of collision
//console.log('proj out', distance.x, distance.y,'dot',dot);
shape.position.add(distance);
}
/**
* Checks for overlaps between two objects using the world QuadTree. Can be GameObject vs. GameObject, GameObject vs. Group or Group vs. Group.
* Checks for overlaps between two objects using the world QuadTree. Can be Sprite vs. Sprite, Sprite vs. Group or Group vs. Group.
* Note: Does not take the objects scrollFactor into account. All overlaps are check in world space.
* @param object1 The first GameObject or Group to check. If null the world.group is used.
* @param object2 The second GameObject or Group to check.
* @param object1 The first Sprite or Group to check. If null the world.group is used.
* @param object2 The second Sprite or Group to check.
* @param notifyCallback A callback function that is called if the objects overlap. The two objects will be passed to this function in the same order in which you passed them to Collision.overlap.
* @param processCallback A callback function that lets you perform additional checks against the two objects if they overlap. If this is set then notifyCallback will only be called if processCallback returns true.
* @param context The context in which the callbacks will be called
* @returns {boolean} true if the objects overlap, otherwise false.
*/
/*
public overlap(object1: Basic = null, object2: Basic = null, notifyCallback = null, processCallback = null, context = null): bool {
public overlap(object1 = null, object2 = null, notifyCallback = null, processCallback = null, context = null): bool {
if (object1 == null)
{
object1 = this._game.world.group;
object1 = this.game.world.group;
}
if (object2 == object1)
@@ -861,23 +830,21 @@ module Phaser.Physics {
object2 = null;
}
QuadTree.divisions = this._game.world.worldDivisions;
QuadTree.divisions = this.worldDivisions;
var quadTree: QuadTree = new QuadTree(this._game.world.bounds.x, this._game.world.bounds.y, this._game.world.bounds.width, this._game.world.bounds.height);
this._quadTree = new QuadTree(this.bounds.x, this.bounds.y, this.bounds.width, this.bounds.height);
quadTree.load(object1, object2, notifyCallback, processCallback, context);
this._quadTree.load(object1, object2, notifyCallback, processCallback, context);
var result: bool = quadTree.execute();
this._quadTreeResult = this._quadTree.execute();
quadTree.destroy();
this._quadTree.destroy();
quadTree = null;
this._quadTree = null;
return result;
return this._quadTreeResult;
}
*/
}
@@ -1,5 +1,5 @@
/// <reference path="../Game.ts" />
/// <reference path="LinkedList.ts" />
/// <reference path="../math/LinkedList.ts" />
/// <reference path="../gameobjects/IGameObject.ts" />
/**
@@ -10,7 +10,7 @@
* or the A list against the B list. Handy for different things!
*/
module Phaser {
module Phaser.Physics {
export class QuadTree extends Rectangle {
@@ -333,7 +333,7 @@ module Phaser {
QuadTree._list = list;
if (objectOrGroup.isGroup == true)
if (objectOrGroup.type == Types.GROUP)
{
this._i = 0;
this._members = <Group> objectOrGroup['members'];
@@ -353,7 +353,7 @@ module Phaser {
{
QuadTree._object = this._basic;
if (QuadTree._object.exists && QuadTree._object.allowCollisions)
if (QuadTree._object.exists && QuadTree._object.body.allowCollisions)
{
this.addObject();
}
@@ -365,7 +365,7 @@ module Phaser {
{
QuadTree._object = objectOrGroup;
if (QuadTree._object.exists && QuadTree._object.allowCollisions)
if (QuadTree._object.exists && QuadTree._object.body.allowCollisions)
{
this.addObject();
}
@@ -379,16 +379,16 @@ module Phaser {
private addObject() {
//If this quad (not its children) lies entirely inside this object, add it here
if (!this._canSubdivide || ((this._leftEdge >= QuadTree._object.collisionMask.x) && (this._rightEdge <= QuadTree._object.collisionMask.right) && (this._topEdge >= QuadTree._object.collisionMask.y) && (this._bottomEdge <= QuadTree._object.collisionMask.bottom)))
if (!this._canSubdivide || ((this._leftEdge >= QuadTree._object.body.bounds.x) && (this._rightEdge <= QuadTree._object.body.bounds.right) && (this._topEdge >= QuadTree._object.body.bounds.y) && (this._bottomEdge <= QuadTree._object.body.bounds.bottom)))
{
this.addToList();
return;
}
//See if the selected object fits completely inside any of the quadrants
if ((QuadTree._object.collisionMask.x > this._leftEdge) && (QuadTree._object.collisionMask.right < this._midpointX))
if ((QuadTree._object.body.bounds.x > this._leftEdge) && (QuadTree._object.body.bounds.right < this._midpointX))
{
if ((QuadTree._object.collisionMask.y > this._topEdge) && (QuadTree._object.collisionMask.bottom < this._midpointY))
if ((QuadTree._object.body.bounds.y > this._topEdge) && (QuadTree._object.body.bounds.bottom < this._midpointY))
{
if (this._northWestTree == null)
{
@@ -399,7 +399,7 @@ module Phaser {
return;
}
if ((QuadTree._object.collisionMask.y > this._midpointY) && (QuadTree._object.collisionMask.bottom < this._bottomEdge))
if ((QuadTree._object.body.bounds.y > this._midpointY) && (QuadTree._object.body.bounds.bottom < this._bottomEdge))
{
if (this._southWestTree == null)
{
@@ -411,9 +411,9 @@ module Phaser {
}
}
if ((QuadTree._object.collisionMask.x > this._midpointX) && (QuadTree._object.collisionMask.right < this._rightEdge))
if ((QuadTree._object.body.bounds.x > this._midpointX) && (QuadTree._object.body.bounds.right < this._rightEdge))
{
if ((QuadTree._object.collisionMask.y > this._topEdge) && (QuadTree._object.collisionMask.bottom < this._midpointY))
if ((QuadTree._object.body.bounds.y > this._topEdge) && (QuadTree._object.body.bounds.bottom < this._midpointY))
{
if (this._northEastTree == null)
{
@@ -424,7 +424,7 @@ module Phaser {
return;
}
if ((QuadTree._object.collisionMask.y > this._midpointY) && (QuadTree._object.collisionMask.bottom < this._bottomEdge))
if ((QuadTree._object.body.bounds.y > this._midpointY) && (QuadTree._object.body.bounds.bottom < this._bottomEdge))
{
if (this._southEastTree == null)
{
@@ -437,7 +437,7 @@ module Phaser {
}
//If it wasn't completely contained we have to check out the partial overlaps
if ((QuadTree._object.collisionMask.right > this._leftEdge) && (QuadTree._object.collisionMask.x < this._midpointX) && (QuadTree._object.collisionMask.bottom > this._topEdge) && (QuadTree._object.collisionMask.y < this._midpointY))
if ((QuadTree._object.body.bounds.right > this._leftEdge) && (QuadTree._object.body.bounds.x < this._midpointX) && (QuadTree._object.body.bounds.bottom > this._topEdge) && (QuadTree._object.body.bounds.y < this._midpointY))
{
if (this._northWestTree == null)
{
@@ -447,7 +447,7 @@ module Phaser {
this._northWestTree.addObject();
}
if ((QuadTree._object.collisionMask.right > this._midpointX) && (QuadTree._object.collisionMask.x < this._rightEdge) && (QuadTree._object.collisionMask.bottom > this._topEdge) && (QuadTree._object.collisionMask.y < this._midpointY))
if ((QuadTree._object.body.bounds.right > this._midpointX) && (QuadTree._object.body.bounds.x < this._rightEdge) && (QuadTree._object.body.bounds.bottom > this._topEdge) && (QuadTree._object.body.bounds.y < this._midpointY))
{
if (this._northEastTree == null)
{
@@ -457,7 +457,7 @@ module Phaser {
this._northEastTree.addObject();
}
if ((QuadTree._object.collisionMask.right > this._midpointX) && (QuadTree._object.collisionMask.x < this._rightEdge) && (QuadTree._object.collisionMask.bottom > this._midpointY) && (QuadTree._object.collisionMask.y < this._bottomEdge))
if ((QuadTree._object.body.bounds.right > this._midpointX) && (QuadTree._object.body.bounds.x < this._rightEdge) && (QuadTree._object.body.bounds.bottom > this._midpointY) && (QuadTree._object.body.bounds.y < this._bottomEdge))
{
if (this._southEastTree == null)
{
@@ -467,7 +467,7 @@ module Phaser {
this._southEastTree.addObject();
}
if ((QuadTree._object.collisionMask.right > this._leftEdge) && (QuadTree._object.collisionMask.x < this._midpointX) && (QuadTree._object.collisionMask.bottom > this._midpointY) && (QuadTree._object.collisionMask.y < this._bottomEdge))
if ((QuadTree._object.body.bounds.right > this._leftEdge) && (QuadTree._object.body.bounds.x < this._midpointX) && (QuadTree._object.body.bounds.bottom > this._midpointY) && (QuadTree._object.body.bounds.y < this._bottomEdge))
{
if (this._southWestTree == null)
{
@@ -561,7 +561,7 @@ module Phaser {
QuadTree._iterator = this._iterator.next;
}
if (QuadTree._object.exists && (QuadTree._object.allowCollisions > 0) && (QuadTree._iterator != null) && (QuadTree._iterator.object != null) && QuadTree._iterator.object.exists && this.overlapNode())
if (QuadTree._object.exists && (QuadTree._object.body.allowCollisions > 0) && (QuadTree._iterator != null) && (QuadTree._iterator.object != null) && QuadTree._iterator.object.exists && this.overlapNode())
{
this._overlapProcessed = true;
}
@@ -608,20 +608,20 @@ module Phaser {
while (QuadTree._iterator != null)
{
if (!QuadTree._object.exists || (QuadTree._object.allowCollisions <= 0))
if (!QuadTree._object.exists || (QuadTree._object.body.allowCollisions <= 0))
{
break;
}
this._checkObject = QuadTree._iterator.object;
if ((QuadTree._object === this._checkObject) || !this._checkObject.exists || (this._checkObject.allowCollisions <= 0))
if ((QuadTree._object === this._checkObject) || !this._checkObject.exists || (this._checkObject.body.allowCollisions <= 0))
{
QuadTree._iterator = QuadTree._iterator.next;
continue;
}
if (QuadTree._object.collisionMask.checkHullIntersection(this._checkObject.collisionMask))
if (QuadTree._object.body.bounds.checkHullIntersection(this._checkObject.body.bounds))
{
//Execute callback functions if they exist
if ((QuadTree._processingCallback == null) || QuadTree._processingCallback(QuadTree._object, this._checkObject))
+6 -21
View File
@@ -54,9 +54,6 @@ module Phaser {
this._camera.postRender();
}
// Physics Debug layer
this._game.world.physics.render();
}
/**
@@ -121,10 +118,10 @@ module Phaser {
// Rotation and Flipped
if (sprite.modified)
{
if (sprite.texture.renderRotation == true && (sprite.rotation !== 0 || sprite.rotationOffset !== 0))
if (sprite.texture.renderRotation == true && (sprite.angle !== 0 || sprite.angleOffset !== 0))
{
this._sin = Math.sin(sprite.game.math.degreesToRadians(sprite.rotationOffset + sprite.rotation));
this._cos = Math.cos(sprite.game.math.degreesToRadians(sprite.rotationOffset + sprite.rotation));
this._sin = Math.sin(sprite.game.math.degreesToRadians(sprite.angleOffset + sprite.angle));
this._cos = Math.cos(sprite.game.math.degreesToRadians(sprite.angleOffset + sprite.angle));
}
// setTransform(a, b, c, d, e, f);
@@ -185,12 +182,6 @@ module Phaser {
sprite.texture.context.restore();
}
//if (this.renderDebug)
//{
// this.renderBounds(camera, cameraOffsetX, cameraOffsetY);
//this.collisionMask.render(camera, cameraOffsetX, cameraOffsetY);
//}
if (this._ga > -1)
{
sprite.texture.context.globalAlpha = this._ga;
@@ -245,10 +236,10 @@ module Phaser {
// Rotation and Flipped
if (scrollZone.modified)
{
if (scrollZone.texture.renderRotation == true && (scrollZone.rotation !== 0 || scrollZone.rotationOffset !== 0))
if (scrollZone.texture.renderRotation == true && (scrollZone.angle !== 0 || scrollZone.angleOffset !== 0))
{
this._sin = Math.sin(scrollZone.game.math.degreesToRadians(scrollZone.rotationOffset + scrollZone.rotation));
this._cos = Math.cos(scrollZone.game.math.degreesToRadians(scrollZone.rotationOffset + scrollZone.rotation));
this._sin = Math.sin(scrollZone.game.math.degreesToRadians(scrollZone.angleOffset + scrollZone.angle));
this._cos = Math.cos(scrollZone.game.math.degreesToRadians(scrollZone.angleOffset + scrollZone.angle));
}
// setTransform(a, b, c, d, e, f);
@@ -300,12 +291,6 @@ module Phaser {
scrollZone.texture.context.restore();
}
//if (this.renderDebug)
//{
// this.renderBounds(camera, cameraOffsetX, cameraOffsetY);
//this.collisionMask.render(camera, cameraOffsetX, cameraOffsetY);
//}
if (this._ga > -1)
{
scrollZone.texture.context.globalAlpha = this._ga;
+4 -5
View File
@@ -23,13 +23,11 @@ Latest Update
TODO:
* Dispatch world resize event
* Removed ignoreGlobalUpdate because it checks exists etc in the Group update, so remove those checks from Sprite.update (same for render)
* Investigate why tweens don't restart after the game pauses
* Fix bug in Tween yoyo + loop combo
* Copy the setTransform from Sprite to Camera
* Move Camera.scroll.x to just Camera.x/y
* Get AABB offset working somehow
* Apply Sprite scaling to Body.bounds
V1.0.0
@@ -49,6 +47,9 @@ V1.0.0
* Added Tween.loop property so they can now re-run themselves indefinitely.
* Added Tween.yoyo property so they can reverse themselves after completing.
* Added Gravity to the Physics component.
* Removed Sprite.rotation - use Sprite.angle instead
* Optimised separateX/Y and overlap so they don't use any temporary vars any more.
* Added the new Physics.Body object to all Sprites. Used for all physics calculations in-game. Will be extended for Fixtures/Joints in future.
V0.9.6
@@ -143,9 +144,7 @@ V0.9.6
* TODO: Game.Time should monitor pause duration
* TODO: Investigate bug re: tilemap collision and animation frames
* TODO: Update tests that use arrow keys and include touch/mouse support (FlxControlHandler style)
* TODO: GameObject.clipRect - won't work with rotation :( have to use context.clip which is crazy expensive, damnit
* TODO: Polygon geom primitive
* TODO: Move GameObject transforms to a single matrix
* TODO: this.target.view.style.cursor = "pointer"; ("default")
* TODO: If the Camera is larger than the Stage size then the rotation offset isn't correct
* TODO: Texture Repeat doesn't scroll, because it's part of the camera not the world, need to think about this more
+1661 -1402
View File
File diff suppressed because it is too large Load Diff