mirror of
https://github.com/photonstorm/phaser
synced 2025-02-16 14:08:28 +00:00
Merge branch 'photonstorm/097'
This commit is contained in:
commit
4695f62d1d
61 changed files with 8721 additions and 15828 deletions
26
GruntFile.js
26
GruntFile.js
|
@ -51,15 +51,23 @@ module.exports = function (grunt) {
|
|||
comments: true
|
||||
}
|
||||
},
|
||||
fx: {
|
||||
src: ['SpecialFX/**/*.ts'],
|
||||
dest: 'build/phaser-fx.js',
|
||||
options: {
|
||||
target: 'ES5',
|
||||
declaration: true,
|
||||
comments: true
|
||||
}
|
||||
}
|
||||
//tests: {
|
||||
// src: ['Tests/**/*.ts'],
|
||||
// options: {
|
||||
// target: 'ES5',
|
||||
// declaration: true,
|
||||
// comments: true
|
||||
// }
|
||||
// }
|
||||
//fx: {
|
||||
// src: ['SpecialFX/**/*.ts'],
|
||||
// dest: 'build/phaser-fx.js',
|
||||
// options: {
|
||||
// target: 'ES5',
|
||||
// declaration: true,
|
||||
// comments: true
|
||||
// }
|
||||
//}
|
||||
},
|
||||
copy: {
|
||||
main: {
|
||||
|
|
|
@ -82,18 +82,6 @@ module Phaser {
|
|||
*/
|
||||
public _raf: RequestAnimationFrame;
|
||||
|
||||
/**
|
||||
* Max allowable accumulation.
|
||||
* @type {number}
|
||||
*/
|
||||
private _maxAccumulation: number = 32;
|
||||
|
||||
/**
|
||||
* Total number of milliseconds elapsed since last update loop.
|
||||
* @type {number}
|
||||
*/
|
||||
private _accumulator: number = 0;
|
||||
|
||||
/**
|
||||
* Milliseconds of time per step of the game loop.
|
||||
* @type {number}
|
||||
|
@ -231,6 +219,12 @@ module Phaser {
|
|||
*/
|
||||
public world: World;
|
||||
|
||||
/**
|
||||
* Reference to the physics manager.
|
||||
* @type {Physics.Manager}
|
||||
*/
|
||||
public physics: Physics.Manager;
|
||||
|
||||
/**
|
||||
* Instance of repeatable random data generator helper.
|
||||
* @type {RandomDataGenerator}
|
||||
|
@ -293,6 +287,7 @@ module Phaser {
|
|||
this.tweens = new TweenManager(this);
|
||||
this.input = new Input(this);
|
||||
this.rnd = new RandomDataGenerator([(Date.now() * Math.random()).toString()]);
|
||||
this.physics = new Physics.Manager(this);
|
||||
|
||||
this.setRenderer(Phaser.Types.RENDERER_CANVAS);
|
||||
|
||||
|
@ -300,12 +295,12 @@ module Phaser {
|
|||
this.stage.boot();
|
||||
this.input.boot();
|
||||
|
||||
this.framerate = 60;
|
||||
this.isBooted = true;
|
||||
|
||||
// Set-up some static helper references
|
||||
DebugUtils.game = this;
|
||||
ColorUtils.game = this;
|
||||
DebugUtils.context = this.stage.context;
|
||||
|
||||
// Display the default game screen?
|
||||
if (this.onInitCallback == null && this.onCreateCallback == null && this.onUpdateCallback == null && this.onRenderCallback == null && this._pendingState == null)
|
||||
|
@ -396,20 +391,8 @@ module Phaser {
|
|||
this.tweens.update();
|
||||
this.input.update();
|
||||
this.stage.update();
|
||||
|
||||
this._accumulator += this.time.delta;
|
||||
|
||||
if (this._accumulator > this._maxAccumulation)
|
||||
{
|
||||
this._accumulator = this._maxAccumulation;
|
||||
}
|
||||
|
||||
while (this._accumulator >= this._step)
|
||||
{
|
||||
this.time.elapsed = this.time.timeScale * (this._step / 1000);
|
||||
this.world.update();
|
||||
this._accumulator = this._accumulator - this._step;
|
||||
}
|
||||
this.physics.update();
|
||||
this.world.update();
|
||||
|
||||
if (this._loadComplete && this.onUpdateCallback)
|
||||
{
|
||||
|
@ -624,21 +607,6 @@ module Phaser {
|
|||
|
||||
}
|
||||
|
||||
public get framerate(): number {
|
||||
return 1000 / this._step;
|
||||
}
|
||||
|
||||
public set framerate(value: number) {
|
||||
|
||||
this._step = 1000 / value;
|
||||
|
||||
if (this._maxAccumulation < this._step)
|
||||
{
|
||||
this._maxAccumulation = this._step;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for overlaps between two objects using the world QuadTree. Can be GameObject vs. GameObject, GameObject vs. Group or Group vs. Group.
|
||||
* Note: Does not take the objects scrollFactor into account. All overlaps are check in world space.
|
||||
|
@ -650,7 +618,8 @@ module Phaser {
|
|||
* @returns {boolean} true if the objects overlap, otherwise false.
|
||||
*/
|
||||
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);
|
||||
//return this.world.physics.overlap(objectOrGroup1, objectOrGroup2, notifyCallback, this.world.physics.separate, context);
|
||||
return false;
|
||||
}
|
||||
|
||||
public get camera(): Camera {
|
||||
|
|
|
@ -52,6 +52,7 @@ module Phaser {
|
|||
* @param {number} maxTime Time given in milliseconds (1000 = 1 sec). If set the speed is adjusted so the source will arrive at destination in the given number of ms
|
||||
*/
|
||||
public moveTowardsObject(source: Sprite, dest: Sprite, speed: number = 60, maxTime: number = 0) {
|
||||
|
||||
var a: number = this.angleBetween(source, dest);
|
||||
|
||||
if (maxTime > 0)
|
||||
|
@ -79,6 +80,8 @@ module Phaser {
|
|||
* @param {number} ySpeedMax The maximum speed in pixels per second in which the sprite can move vertically
|
||||
*/
|
||||
public accelerateTowardsObject(source: Sprite, dest: Sprite, speed: number, xSpeedMax: number, ySpeedMax: number) {
|
||||
|
||||
/*
|
||||
var a: number = this.angleBetween(source, dest);
|
||||
|
||||
source.body.velocity.x = 0;
|
||||
|
@ -89,6 +92,7 @@ module Phaser {
|
|||
|
||||
source.body.maxVelocity.x = xSpeedMax;
|
||||
source.body.maxVelocity.y = ySpeedMax;
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
|
@ -103,6 +107,7 @@ module Phaser {
|
|||
* @param {number} maxTime Time given in milliseconds (1000 = 1 sec). If set the speed is adjusted so the source will arrive at destination in the given number of ms
|
||||
*/
|
||||
public moveTowardsMouse(source: Sprite, speed: number = 60, maxTime: number = 0) {
|
||||
|
||||
var a: number = this.angleBetweenMouse(source);
|
||||
|
||||
if (maxTime > 0)
|
||||
|
@ -129,6 +134,8 @@ module Phaser {
|
|||
* @param {number} ySpeedMax The maximum speed in pixels per second in which the sprite can move vertically
|
||||
*/
|
||||
public accelerateTowardsMouse(source: Sprite, speed: number, xSpeedMax: number, ySpeedMax: number) {
|
||||
|
||||
/*
|
||||
var a: number = this.angleBetweenMouse(source);
|
||||
|
||||
source.body.velocity.x = 0;
|
||||
|
@ -139,6 +146,8 @@ module Phaser {
|
|||
|
||||
source.body.maxVelocity.x = xSpeedMax;
|
||||
source.body.maxVelocity.y = ySpeedMax;
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -153,6 +162,7 @@ module Phaser {
|
|||
* @param {number} maxTime Time given in milliseconds (1000 = 1 sec). If set the speed is adjusted so the source will arrive at destination in the given number of ms
|
||||
*/
|
||||
public moveTowardsPoint(source: Sprite, target: Point, speed: number = 60, maxTime: number = 0) {
|
||||
|
||||
var a: number = this.angleBetweenPoint(source, target);
|
||||
|
||||
if (maxTime > 0)
|
||||
|
@ -179,6 +189,8 @@ module Phaser {
|
|||
* @param {number} ySpeedMax The maximum speed in pixels per second in which the sprite can move vertically
|
||||
*/
|
||||
public accelerateTowardsPoint(source: Sprite, target: Point, speed: number, xSpeedMax: number, ySpeedMax: number) {
|
||||
|
||||
/*
|
||||
var a: number = this.angleBetweenPoint(source, target);
|
||||
|
||||
source.body.velocity.x = 0;
|
||||
|
@ -189,6 +201,8 @@ module Phaser {
|
|||
|
||||
source.body.maxVelocity.x = xSpeedMax;
|
||||
source.body.maxVelocity.y = ySpeedMax;
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -240,6 +254,7 @@ module Phaser {
|
|||
* @return {number} The angle (in radians unless asDegrees is true)
|
||||
*/
|
||||
public angleBetweenPoint(a: Sprite, target: Point, asDegrees: bool = false): number {
|
||||
|
||||
var dx: number = (target.x) - (a.x + a.transform.origin.x);
|
||||
var dy: number = (target.y) - (a.y + a.transform.origin.y);
|
||||
|
||||
|
@ -251,6 +266,7 @@ module Phaser {
|
|||
{
|
||||
return Math.atan2(dy, dx);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -287,6 +303,8 @@ module Phaser {
|
|||
* @return {Point} An Point where Point.x contains the velocity x value and Point.y contains the velocity y value
|
||||
*/
|
||||
public velocityFromFacing(parent: Sprite, speed: number): Point {
|
||||
|
||||
/*
|
||||
var a: number;
|
||||
|
||||
if (parent.body.facing == Types.LEFT)
|
||||
|
@ -307,6 +325,9 @@ module Phaser {
|
|||
}
|
||||
|
||||
return new Point(Math.cos(a) * speed, Math.sin(a) * speed);
|
||||
*/
|
||||
|
||||
return new Point;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -56,9 +56,7 @@
|
|||
<TypeScriptOutFile>../build/phaser.js</TypeScriptOutFile>
|
||||
<TypeScriptGeneratesDeclarations>true</TypeScriptGeneratesDeclarations>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="physics\arcade\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<ItemGroup>
|
||||
<Content Include="components\animation\AnimationManager.js">
|
||||
<DependentUpon>AnimationManager.ts</DependentUpon>
|
||||
|
@ -143,7 +141,6 @@
|
|||
<TypeScriptCompile Include="renderers\CanvasRenderer.ts" />
|
||||
<TypeScriptCompile Include="Statics.ts" />
|
||||
<TypeScriptCompile Include="renderers\HeadlessRenderer.ts" />
|
||||
<TypeScriptCompile Include="physics\PhysicsManager.ts" />
|
||||
<TypeScriptCompile Include="physics\Body.ts" />
|
||||
<TypeScriptCompile Include="math\QuadTree.ts" />
|
||||
<TypeScriptCompile Include="math\Mat3.ts" />
|
||||
|
@ -177,83 +174,72 @@
|
|||
<Content Include="Motion.js">
|
||||
<DependentUpon>Motion.ts</DependentUpon>
|
||||
</Content>
|
||||
<TypeScriptCompile Include="physics\ArcadePhysics.ts" />
|
||||
<TypeScriptCompile Include="physics\advanced\Body.ts" />
|
||||
<Content Include="physics\advanced\Body.js">
|
||||
<DependentUpon>Body.ts</DependentUpon>
|
||||
</Content>
|
||||
<TypeScriptCompile Include="physics\advanced\Bounds.ts" />
|
||||
<Content Include="physics\advanced\Bounds.js">
|
||||
<DependentUpon>Bounds.ts</DependentUpon>
|
||||
</Content>
|
||||
<TypeScriptCompile Include="physics\advanced\Contact.ts" />
|
||||
<TypeScriptCompile Include="physics\advanced\Collision.ts" />
|
||||
<Content Include="physics\advanced\Collision.js">
|
||||
<DependentUpon>Collision.ts</DependentUpon>
|
||||
</Content>
|
||||
<Content Include="physics\advanced\Contact.js">
|
||||
<DependentUpon>Contact.ts</DependentUpon>
|
||||
</Content>
|
||||
<TypeScriptCompile Include="physics\advanced\ContactSolver.ts" />
|
||||
<Content Include="physics\advanced\ContactSolver.js">
|
||||
<DependentUpon>ContactSolver.ts</DependentUpon>
|
||||
</Content>
|
||||
<TypeScriptCompile Include="physics\advanced\Manager.ts" />
|
||||
<TypeScriptCompile Include="physics\advanced\joints\IJoint.ts" />
|
||||
<Content Include="physics\advanced\joints\IJoint.js">
|
||||
<DependentUpon>IJoint.ts</DependentUpon>
|
||||
</Content>
|
||||
<TypeScriptCompile Include="physics\advanced\joints\Joint.ts" />
|
||||
<Content Include="physics\advanced\joints\Joint.js">
|
||||
<DependentUpon>Joint.ts</DependentUpon>
|
||||
</Content>
|
||||
<Content Include="physics\advanced\Manager.js">
|
||||
<DependentUpon>Manager.ts</DependentUpon>
|
||||
</Content>
|
||||
<TypeScriptCompile Include="physics\advanced\shapes\Shape.ts" />
|
||||
<TypeScriptCompile Include="physics\advanced\shapes\IShape.ts" />
|
||||
<TypeScriptCompile Include="physics\advanced\shapes\Box.ts" />
|
||||
<TypeScriptCompile Include="physics\advanced\Plane.ts" />
|
||||
<Content Include="physics\advanced\Plane.js">
|
||||
<DependentUpon>Plane.ts</DependentUpon>
|
||||
</Content>
|
||||
<Content Include="physics\advanced\shapes\Box.js">
|
||||
<DependentUpon>Box.ts</DependentUpon>
|
||||
</Content>
|
||||
<TypeScriptCompile Include="physics\advanced\shapes\Circle.ts" />
|
||||
<Content Include="physics\advanced\shapes\Circle.js">
|
||||
<DependentUpon>Circle.ts</DependentUpon>
|
||||
</Content>
|
||||
<Content Include="physics\advanced\shapes\IShape.js">
|
||||
<DependentUpon>IShape.ts</DependentUpon>
|
||||
</Content>
|
||||
<TypeScriptCompile Include="physics\advanced\shapes\Poly.ts" />
|
||||
<Content Include="physics\advanced\shapes\Poly.js">
|
||||
<DependentUpon>Poly.ts</DependentUpon>
|
||||
</Content>
|
||||
<TypeScriptCompile Include="physics\advanced\shapes\Segment.ts" />
|
||||
<Content Include="physics\advanced\shapes\Segment.js">
|
||||
<DependentUpon>Segment.ts</DependentUpon>
|
||||
</Content>
|
||||
<Content Include="physics\advanced\shapes\Shape.js">
|
||||
<DependentUpon>Shape.ts</DependentUpon>
|
||||
</Content>
|
||||
<TypeScriptCompile Include="physics\advanced\shapes\Triangle.ts" />
|
||||
<Content Include="physics\advanced\shapes\Triangle.js">
|
||||
<DependentUpon>Triangle.ts</DependentUpon>
|
||||
</Content>
|
||||
<TypeScriptCompile Include="physics\advanced\Space.ts" />
|
||||
<Content Include="physics\advanced\Space.js">
|
||||
<DependentUpon>Space.ts</DependentUpon>
|
||||
</Content>
|
||||
<Content Include="physics\ArcadePhysics.js">
|
||||
<DependentUpon>ArcadePhysics.ts</DependentUpon>
|
||||
</Content>
|
||||
<Content Include="physics\Body.js">
|
||||
<DependentUpon>Body.ts</DependentUpon>
|
||||
</Content>
|
||||
<Content Include="physics\PhysicsManager.js">
|
||||
<DependentUpon>PhysicsManager.ts</DependentUpon>
|
||||
<TypeScriptCompile Include="physics\Bounds.ts" />
|
||||
<Content Include="physics\Bounds.js">
|
||||
<DependentUpon>Bounds.ts</DependentUpon>
|
||||
</Content>
|
||||
<TypeScriptCompile Include="physics\Collision.ts" />
|
||||
<Content Include="physics\Collision.js">
|
||||
<DependentUpon>Collision.ts</DependentUpon>
|
||||
</Content>
|
||||
<TypeScriptCompile Include="physics\Contact.ts" />
|
||||
<Content Include="physics\Contact.js">
|
||||
<DependentUpon>Contact.ts</DependentUpon>
|
||||
</Content>
|
||||
<TypeScriptCompile Include="physics\ContactSolver.ts" />
|
||||
<Content Include="physics\ContactSolver.js">
|
||||
<DependentUpon>ContactSolver.ts</DependentUpon>
|
||||
</Content>
|
||||
<TypeScriptCompile Include="physics\Manager.ts" />
|
||||
<TypeScriptCompile Include="physics\joints\IJoint.ts" />
|
||||
<Content Include="physics\joints\IJoint.js">
|
||||
<DependentUpon>IJoint.ts</DependentUpon>
|
||||
</Content>
|
||||
<TypeScriptCompile Include="physics\joints\Joint.ts" />
|
||||
<Content Include="physics\joints\Joint.js">
|
||||
<DependentUpon>Joint.ts</DependentUpon>
|
||||
</Content>
|
||||
<Content Include="physics\Manager.js">
|
||||
<DependentUpon>Manager.ts</DependentUpon>
|
||||
</Content>
|
||||
<TypeScriptCompile Include="physics\Plane.ts" />
|
||||
<Content Include="physics\Plane.js">
|
||||
<DependentUpon>Plane.ts</DependentUpon>
|
||||
</Content>
|
||||
<TypeScriptCompile Include="physics\Space.ts" />
|
||||
<TypeScriptCompile Include="physics\shapes\Box.ts" />
|
||||
<Content Include="physics\shapes\Box.js">
|
||||
<DependentUpon>Box.ts</DependentUpon>
|
||||
</Content>
|
||||
<TypeScriptCompile Include="physics\shapes\Circle.ts" />
|
||||
<Content Include="physics\shapes\Circle.js">
|
||||
<DependentUpon>Circle.ts</DependentUpon>
|
||||
</Content>
|
||||
<TypeScriptCompile Include="physics\shapes\IShape.ts" />
|
||||
<Content Include="physics\shapes\IShape.js">
|
||||
<DependentUpon>IShape.ts</DependentUpon>
|
||||
</Content>
|
||||
<TypeScriptCompile Include="physics\shapes\Poly.ts" />
|
||||
<Content Include="physics\shapes\Poly.js">
|
||||
<DependentUpon>Poly.ts</DependentUpon>
|
||||
</Content>
|
||||
<TypeScriptCompile Include="physics\shapes\Segment.ts" />
|
||||
<Content Include="physics\shapes\Segment.js">
|
||||
<DependentUpon>Segment.ts</DependentUpon>
|
||||
</Content>
|
||||
<TypeScriptCompile Include="physics\shapes\Shape.ts" />
|
||||
<Content Include="physics\shapes\Shape.js">
|
||||
<DependentUpon>Shape.ts</DependentUpon>
|
||||
</Content>
|
||||
<TypeScriptCompile Include="physics\shapes\Triangle.ts" />
|
||||
<Content Include="physics\shapes\Triangle.js">
|
||||
<DependentUpon>Triangle.ts</DependentUpon>
|
||||
</Content>
|
||||
<Content Include="physics\Space.js">
|
||||
<DependentUpon>Space.ts</DependentUpon>
|
||||
</Content>
|
||||
<Content Include="renderers\HeadlessRenderer.js">
|
||||
<DependentUpon>HeadlessRenderer.ts</DependentUpon>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/// <reference path="cameras/CameraManager.ts" />
|
||||
/// <reference path="core/Group.ts" />
|
||||
/// <reference path="geom/Rectangle.ts" />
|
||||
/// <reference path="physics/PhysicsManager.ts" />
|
||||
/// <reference path="physics/Manager.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - World
|
||||
|
@ -59,10 +59,10 @@ module Phaser {
|
|||
public bounds: Rectangle;
|
||||
|
||||
/**
|
||||
* Reference to the physics manager.
|
||||
* @type {Physics.PhysicsManager}
|
||||
* The Gravity of the World (defaults to 0,0, or no gravity at all)
|
||||
* @type {Vec2}
|
||||
*/
|
||||
public physics: Physics.PhysicsManager;
|
||||
public gravity: Phaser.Vec2;
|
||||
|
||||
/**
|
||||
* Object container stores every object created with `create*` methods.
|
||||
|
@ -81,8 +81,6 @@ module Phaser {
|
|||
|
||||
this.group = new Group(this._game, 0);
|
||||
|
||||
this.physics = new Physics.PhysicsManager(this._game, this.width, this.height);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -90,7 +88,6 @@ module Phaser {
|
|||
*/
|
||||
public update() {
|
||||
|
||||
//this.physics.update();
|
||||
this.group.update();
|
||||
this.cameras.update();
|
||||
|
||||
|
@ -101,7 +98,6 @@ module Phaser {
|
|||
*/
|
||||
public postUpdate() {
|
||||
|
||||
//this.physics.postUpdate();
|
||||
this.group.postUpdate();
|
||||
this.cameras.postUpdate();
|
||||
|
||||
|
@ -112,7 +108,6 @@ module Phaser {
|
|||
*/
|
||||
public destroy() {
|
||||
|
||||
//this.physics.destroy();
|
||||
this.group.destroy();
|
||||
this.cameras.destroy();
|
||||
|
||||
|
@ -125,7 +120,7 @@ module Phaser {
|
|||
* @param height {number} New height of the world.
|
||||
* @param [updateCameraBounds] {boolean} Update camera bounds automatically or not. Default to true.
|
||||
*/
|
||||
public setSize(width: number, height: number, updateCameraBounds: bool = true, updatePhysicsBounds: bool = true) {
|
||||
public setSize(width: number, height: number, updateCameraBounds: bool = true) {
|
||||
|
||||
this.bounds.width = width;
|
||||
this.bounds.height = height;
|
||||
|
@ -135,11 +130,6 @@ module Phaser {
|
|||
this._game.camera.setBounds(0, 0, width, height);
|
||||
}
|
||||
|
||||
if (updatePhysicsBounds == true)
|
||||
{
|
||||
//this.physics.bounds.copyFrom(this.bounds);
|
||||
}
|
||||
|
||||
// dispatch world resize event
|
||||
|
||||
}
|
||||
|
|
|
@ -375,8 +375,7 @@ module Phaser {
|
|||
this._tempBlockResults = [];
|
||||
this.getTempBlock(this._tempTileX, this._tempTileY, this._tempTileW, this._tempTileH, true);
|
||||
|
||||
Phaser.Physics.PhysicsManager.TILE_OVERLAP = false;
|
||||
|
||||
/*
|
||||
for (var r = 0; r < this._tempTileBlock.length; r++)
|
||||
{
|
||||
if (this._game.world.physics.separateTile(object, this._tempTileBlock[r].x * this.tileWidth, this._tempTileBlock[r].y * this.tileHeight, this.tileWidth, this.tileHeight, this._tempTileBlock[r].tile.mass, this._tempTileBlock[r].tile.collideLeft, this._tempTileBlock[r].tile.collideRight, this._tempTileBlock[r].tile.collideUp, this._tempTileBlock[r].tile.collideDown, this._tempTileBlock[r].tile.separateX, this._tempTileBlock[r].tile.separateY) == true)
|
||||
|
@ -384,6 +383,7 @@ module Phaser {
|
|||
this._tempBlockResults.push({ x: this._tempTileBlock[r].x, y: this._tempTileBlock[r].y, tile: this._tempTileBlock[r].tile });
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
return this._tempBlockResults;
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/// <reference path="../Game.ts" />
|
||||
/// <reference path="../math/Mat3.ts" />
|
||||
/// <reference path="../geom/Point.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - Components - Transform
|
||||
|
@ -98,7 +99,7 @@ module Phaser.Components {
|
|||
this._halfSize.y = this.parent.height / 2;
|
||||
this._offset.x = this.origin.x * this.parent.width;
|
||||
this._offset.y = this.origin.y * this.parent.height;
|
||||
this._angle = Math.atan2(this.halfHeight - this._offset.y, this.halfWidth - this._offset.x);
|
||||
this._angle = Math.atan2(this.halfHeight - this._offset.x, this.halfWidth - this._offset.y);
|
||||
this._distance = Math.sqrt(((this._offset.x - this._halfSize.x) * (this._offset.x - this._halfSize.x)) + ((this._offset.y - this._halfSize.y) * (this._offset.y - this._halfSize.y)));
|
||||
this._size.x = this.parent.width;
|
||||
this._size.y = this.parent.height;
|
||||
|
@ -183,7 +184,7 @@ module Phaser.Components {
|
|||
dirty = true;
|
||||
}
|
||||
|
||||
// If it has moved, updated the edges and center
|
||||
// If it has moved, update the edges and center
|
||||
if (dirty || this.parent.x != this._pos.x || this.parent.y != this._pos.y)
|
||||
{
|
||||
this.center.x = this.parent.x + this._distance * this._scA.y;
|
||||
|
@ -240,22 +241,22 @@ module Phaser.Components {
|
|||
/**
|
||||
* Scale of the object. A scale of 1.0 is the original size. 0.5 half size. 2.0 double sized.
|
||||
*/
|
||||
public scale: Phaser.Vec2;
|
||||
public scale: Vec2;
|
||||
|
||||
/**
|
||||
* Skew the object along the x and y axis. A skew value of 0 is no skew.
|
||||
*/
|
||||
public skew: Phaser.Vec2;
|
||||
public skew: Vec2;
|
||||
|
||||
/**
|
||||
* The influence of camera movement upon the object, if supported.
|
||||
*/
|
||||
public scrollFactor: Phaser.Vec2;
|
||||
public scrollFactor: Vec2;
|
||||
|
||||
/**
|
||||
* The origin is the point around which scale and rotation takes place and defaults to the top-left of the sprite.
|
||||
*/
|
||||
public origin: Phaser.Vec2;
|
||||
public origin: Vec2;
|
||||
|
||||
/**
|
||||
* This value is added to the rotation of the object.
|
||||
|
|
|
@ -93,12 +93,13 @@ module Phaser {
|
|||
*/
|
||||
public checkFrameName(name: string): bool {
|
||||
|
||||
if (this._frameNames[name])
|
||||
|
||||
if (this._frameNames[name] == null)
|
||||
{
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -263,6 +263,7 @@ module Phaser.Components.Sprite {
|
|||
|
||||
if (this.enabled)
|
||||
{
|
||||
this.enabled = false;
|
||||
this.game.input.removeGameObject(this.indexID);
|
||||
}
|
||||
|
||||
|
@ -578,7 +579,9 @@ module Phaser.Components.Sprite {
|
|||
if (this.dragFromCenter)
|
||||
{
|
||||
// Move the sprite to the middle of the pointer
|
||||
this._dragPoint.setTo(-this.sprite.worldView.halfWidth, -this.sprite.worldView.halfHeight);
|
||||
//this._dragPoint.setTo(-this.sprite.worldView.halfWidth, -this.sprite.worldView.halfHeight);
|
||||
//this._dragPoint.setTo(this.sprite.transform.center.x, this.sprite.transform.center.y);
|
||||
this._dragPoint.setTo(this.sprite.x - pointer.x, this.sprite.y - pointer.y);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -527,6 +527,8 @@ module Phaser {
|
|||
*/
|
||||
public remove(object, splice: bool = false) {
|
||||
|
||||
console.log('removing from group');
|
||||
|
||||
this._i = this.members.indexOf(object);
|
||||
|
||||
if (this._i < 0 || (this._i >= this.members.length))
|
||||
|
@ -544,6 +546,8 @@ module Phaser {
|
|||
this.members[this._i] = null;
|
||||
}
|
||||
|
||||
console.log('nulled');
|
||||
|
||||
if (object['events'])
|
||||
{
|
||||
object['events'].onRemovedFromGroup.dispatch(object, this);
|
||||
|
@ -615,7 +619,7 @@ module Phaser {
|
|||
public bringToTop(child): bool {
|
||||
|
||||
// If child not in this group, or is already at the top of the group, return false
|
||||
if (child.group.ID != this.ID || child.z == this._zCounter)
|
||||
if (!child || child.group == null || child.group.ID != this.ID || child.z == this._zCounter)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -238,19 +238,19 @@ module Phaser {
|
|||
|
||||
if (collide > 0)
|
||||
{
|
||||
particle.body.allowCollisions = Types.ANY;
|
||||
//particle.body.allowCollisions = Types.ANY;
|
||||
particle.body.type = Types.BODY_DYNAMIC;
|
||||
particle.width *= collide;
|
||||
particle.height *= collide;
|
||||
}
|
||||
else
|
||||
{
|
||||
particle.body.allowCollisions = Types.NONE;
|
||||
//particle.body.allowCollisions = Types.NONE;
|
||||
}
|
||||
|
||||
particle.exists = false;
|
||||
// Center the origin for rotation assistance
|
||||
particle.transform.origin.setTo(particle.body.bounds.halfWidth, particle.body.bounds.halfHeight);
|
||||
//particle.transform.origin.setTo(particle.body.bounds.halfWidth, particle.body.bounds.halfHeight);
|
||||
|
||||
this.add(particle);
|
||||
|
||||
|
@ -363,7 +363,7 @@ module Phaser {
|
|||
var particle: Particle = this.recycle(Particle);
|
||||
|
||||
particle.lifespan = this.lifespan;
|
||||
particle.body.bounce.setTo(this.bounce, this.bounce);
|
||||
//particle.body.bounce.setTo(this.bounce, this.bounce);
|
||||
SpriteUtils.reset(particle, this.x - (particle.width >> 1) + this.game.math.random() * this.width, this.y - (particle.height >> 1) + this.game.math.random() * this.height);
|
||||
particle.visible = true;
|
||||
|
||||
|
@ -385,7 +385,7 @@ module Phaser {
|
|||
particle.body.velocity.y = this.minParticleSpeed.y;
|
||||
}
|
||||
|
||||
particle.body.acceleration.y = this.gravity;
|
||||
//particle.body.acceleration.y = this.gravity;
|
||||
|
||||
if (this.minRotation != this.maxRotation && this.minRotation !== 0 && this.maxRotation !== 0)
|
||||
{
|
||||
|
@ -401,8 +401,8 @@ module Phaser {
|
|||
particle.rotation = this.game.math.random() * 360 - 180;
|
||||
}
|
||||
|
||||
particle.body.drag.x = this.particleDrag.x;
|
||||
particle.body.drag.y = this.particleDrag.y;
|
||||
//particle.body.drag.x = this.particleDrag.x;
|
||||
//particle.body.drag.y = this.particleDrag.y;
|
||||
particle.onEmit();
|
||||
|
||||
}
|
||||
|
@ -457,8 +457,8 @@ module Phaser {
|
|||
* @param Object {object} The <code>Object</code> that you want to sync up with.
|
||||
*/
|
||||
public at(object: Sprite) {
|
||||
this.x = object.body.bounds.halfWidth - (this.width >> 1);
|
||||
this.y = object.body.bounds.halfHeight - (this.height >> 1);
|
||||
//this.x = object.body.bounds.halfWidth - (this.width >> 1);
|
||||
//this.y = object.body.bounds.halfHeight - (this.height >> 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -72,10 +72,25 @@ module Phaser {
|
|||
* @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 = '', frame? = null, bodyType?: number = Phaser.Types.BODY_DYNAMIC): Sprite {
|
||||
public sprite(x: number, y: number, key?: string = '', frame? = null, bodyType?: number = Phaser.Types.BODY_DISABLED): Sprite {
|
||||
return <Sprite> this._world.group.add(new Sprite(this._game, x, y, key, frame, bodyType));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new Sprite with the physics automatically created and set to DYNAMIC. The Sprite position offset is set to its center.
|
||||
*
|
||||
* @param x {number} X position of the new sprite.
|
||||
* @param y {number} Y position of the new sprite.
|
||||
* @param [key] {string} The image key as defined in the Game.Cache to use as the texture for this sprite
|
||||
* @param [frame] {string|number} If the sprite uses an image from a texture atlas or sprite sheet you can pass the frame here. Either a number for a frame ID or a string for a frame name.
|
||||
* @param [bodyType] {number} The physics body type of the object (defaults to BODY_DYNAMIC)
|
||||
* @param [shapeType] The default body shape is either 0 for a Box or 1 for a Circle. See Sprite.body.addShape for custom shapes (polygons, etc)
|
||||
* @returns {Sprite} The newly created sprite object.
|
||||
*/
|
||||
public physicsSprite(x: number, y: number, key?: string = '', frame? = null, bodyType?: number = Phaser.Types.BODY_DYNAMIC, shapeType?:number = 0): Sprite {
|
||||
return <Sprite> this._world.group.add(new Sprite(this._game, x, y, key, frame, bodyType, shapeType));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new DynamicTexture with specific size.
|
||||
*
|
||||
|
|
|
@ -22,7 +22,6 @@ module Phaser {
|
|||
|
||||
this.body.type = Types.BODY_DYNAMIC;
|
||||
this.lifespan = 0;
|
||||
this.friction = 500;
|
||||
|
||||
}
|
||||
|
||||
|
@ -34,15 +33,7 @@ module Phaser {
|
|||
public lifespan: number;
|
||||
|
||||
/**
|
||||
* Determines how quickly the particles come to rest on the ground.
|
||||
* Only used if the particle has gravity-like acceleration applied.
|
||||
* @default 500
|
||||
*/
|
||||
public friction: number;
|
||||
|
||||
/**
|
||||
* The particle's main update logic. Basically it checks to see if it should
|
||||
* be dead yet, and then has some special bounce behavior if there is some gravity on it.
|
||||
* The particle's main update logic. Basically it checks to see if it should be dead yet.
|
||||
*/
|
||||
public update() {
|
||||
|
||||
|
@ -59,42 +50,6 @@ module Phaser {
|
|||
this.kill();
|
||||
}
|
||||
|
||||
//simpler bounce/spin behavior for now
|
||||
if (this.body.touching)
|
||||
{
|
||||
if (this.body.angularVelocity != 0)
|
||||
{
|
||||
this.body.angularVelocity = -this.body.angularVelocity;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.body.acceleration.y > 0) //special behavior for particles with gravity
|
||||
{
|
||||
if (this.body.touching & Types.FLOOR)
|
||||
{
|
||||
this.body.drag.x = this.friction;
|
||||
|
||||
if (!(this.body.wasTouching & Types.FLOOR))
|
||||
{
|
||||
if (this.body.velocity.y < -this.body.bounce.y * 10)
|
||||
{
|
||||
if (this.body.angularVelocity != 0)
|
||||
{
|
||||
this.body.angularVelocity *= -this.body.bounce.y;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.body.velocity.y = 0;
|
||||
this.body.angularVelocity = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.body.drag.x = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -23,9 +23,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 [bodyType] {number} The physics body type of the object (defaults to BODY_DYNAMIC)
|
||||
* @param [bodyType] {number} The physics body type of the object (defaults to BODY_DISABLED)
|
||||
* @param [shapeType] {number} The physics shape the body will consist of (either Box (0) or Circle (1), for custom types see body.addShape)
|
||||
*/
|
||||
constructor(game: Game, x?: number = 0, y?: number = 0, key?: string = null, frame? = null, bodyType?: number = Phaser.Types.BODY_DYNAMIC) {
|
||||
constructor(game: Game, x?: number = 0, y?: number = 0, key?: string = null, frame? = null, bodyType?: number = Phaser.Types.BODY_DISABLED, shapeType?:number = 0) {
|
||||
|
||||
this.game = game;
|
||||
this.type = Phaser.Types.SPRITE;
|
||||
|
@ -67,7 +68,13 @@ module Phaser {
|
|||
}
|
||||
}
|
||||
|
||||
this.body = new Phaser.Physics.Body(this, bodyType);
|
||||
if (bodyType !== Phaser.Types.BODY_DISABLED)
|
||||
{
|
||||
this.body = new Phaser.Physics.Body(this, bodyType, 0, 0, shapeType);
|
||||
this.game.physics.addBody(this.body);
|
||||
this.transform.origin.setTo(0.5, 0.5);
|
||||
}
|
||||
|
||||
this.worldView = new Rectangle(x, y, this.width, this.height);
|
||||
this.cameraView = new Rectangle(x, y, this.width, this.height);
|
||||
|
||||
|
@ -118,7 +125,7 @@ module Phaser {
|
|||
/**
|
||||
* Sprite physics body.
|
||||
*/
|
||||
public body: Phaser.Physics.Body;
|
||||
public body: Phaser.Physics.Body = null;
|
||||
|
||||
/**
|
||||
* The texture used to render the Sprite.
|
||||
|
@ -268,8 +275,6 @@ module Phaser {
|
|||
|
||||
this.worldView.x = (this.x * this.transform.scrollFactor.x) - (this.width * this.transform.origin.x);
|
||||
this.worldView.y = (this.y * this.transform.scrollFactor.y) - (this.height * this.transform.origin.y);
|
||||
//this.worldView.x = this.x * this.transform.scrollFactor.x;
|
||||
//this.worldView.y = this.y * this.transform.scrollFactor.y;
|
||||
this.worldView.width = this.width;
|
||||
this.worldView.height = this.height;
|
||||
|
||||
|
@ -281,7 +286,7 @@ module Phaser {
|
|||
}
|
||||
|
||||
/**
|
||||
* Override this function to update your class's position and appearance.
|
||||
* Override this function to update your sprites position and appearance.
|
||||
*/
|
||||
public update() {
|
||||
}
|
||||
|
@ -292,7 +297,6 @@ module Phaser {
|
|||
public postUpdate() {
|
||||
|
||||
this.animations.update();
|
||||
this.body.postUpdate();
|
||||
|
||||
/*
|
||||
if (this.worldBounds != null)
|
||||
|
|
|
@ -229,6 +229,12 @@ module Phaser {
|
|||
{
|
||||
var layer: TilemapLayer = new TilemapLayer(this.game, this, key, Tilemap.FORMAT_TILED_JSON, json.layers[i].name, json.tilewidth, json.tileheight);
|
||||
|
||||
// Check it's a data layer
|
||||
if (!json.layers[i].data)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
layer.alpha = json.layers[i].opacity;
|
||||
layer.visible = json.layers[i].visible;
|
||||
layer.tileMargin = json.tilesets[0].margin;
|
||||
|
|
|
@ -507,6 +507,7 @@ module Phaser {
|
|||
|
||||
if (this.inputObjects[index])
|
||||
{
|
||||
console.log('object removed from the input manager', index);
|
||||
this.inputObjects[index] = null;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ module Phaser {
|
|||
* @param {Number} height Desired height of this node.
|
||||
* @param {Number} parent The parent branch or node. Pass null to create a root.
|
||||
*/
|
||||
constructor(manager: Phaser.Physics.PhysicsManager, x: number, y: number, width: number, height: number, parent: QuadTree = null) {
|
||||
constructor(manager: Phaser.Physics.Manager, x: number, y: number, width: number, height: number, parent: QuadTree = null) {
|
||||
|
||||
super(x, y, width, height);
|
||||
|
||||
|
@ -104,7 +104,7 @@ module Phaser {
|
|||
private _overlapProcessed: bool;
|
||||
private _checkObject;
|
||||
|
||||
public static physics: Phaser.Physics.PhysicsManager;
|
||||
public static physics: Phaser.Physics.Manager;
|
||||
|
||||
/**
|
||||
* Flag for specifying that you want to add an object to the A list.
|
||||
|
@ -625,7 +625,7 @@ module Phaser {
|
|||
continue;
|
||||
}
|
||||
|
||||
//if (QuadTree._object.body.bounds.checkHullIntersection(this._checkObject.body.bounds))
|
||||
/*
|
||||
if (QuadTree.physics.checkHullIntersection(QuadTree._object.body, this._checkObject.body))
|
||||
{
|
||||
//Execute callback functions if they exist
|
||||
|
@ -646,6 +646,7 @@ module Phaser {
|
|||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
QuadTree._iterator = QuadTree._iterator.next;
|
||||
|
||||
|
|
|
@ -23,6 +23,8 @@ module Phaser {
|
|||
this.x = x;
|
||||
this.y = y;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -68,7 +68,7 @@ module Phaser {
|
|||
* @param {Vec2} out The output Vec2 that is the result of the operation.
|
||||
* @return {Vec2} A Vec2 that is the scaled vector.
|
||||
*/
|
||||
static scale(a: Vec2, s: number, out?: Vec2 = new Vec2): Vec2 {
|
||||
static scale(a: Phaser.Vec2, s: number, out?: Phaser.Vec2 = new Phaser.Vec2): Phaser.Vec2 {
|
||||
return out.setTo(a.x * s, a.y * s);
|
||||
}
|
||||
|
||||
|
@ -212,7 +212,7 @@ module Phaser {
|
|||
* @param {Vec2} out The output Vec2 that is the result of the operation.
|
||||
* @return {Vec2} A Vec2.
|
||||
*/
|
||||
static normalRightHand(a: Vec2, out?: Vec2 = this): Vec2 {
|
||||
static normalRightHand(a: Vec2, out?: Vec2 = new Vec2): Vec2 {
|
||||
return out.setTo(a.y * -1, a.x);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,19 +1,3 @@
|
|||
/**
|
||||
* Phaser
|
||||
*
|
||||
* v1.0.0 - June XX 2013
|
||||
*
|
||||
* A small and feature-packed 2D canvas game framework born from the firey pits of Flixel and Kiwi.
|
||||
*
|
||||
* Richard Davey (@photonstorm)
|
||||
*
|
||||
* Many thanks to Adam Saltsman (@ADAMATOMIC) for releasing Flixel, from both which Phaser
|
||||
* and my love of game development took a lot of inspiration.
|
||||
*
|
||||
* "If you want your children to be intelligent, read them fairy tales."
|
||||
* "If you want them to be more intelligent, read them more fairy tales."
|
||||
* -- Albert Einstein
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
Phaser.VERSION = 'Phaser version 1.0.0';
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,62 +1,113 @@
|
|||
/// <reference path="../math/Vec2.ts" />
|
||||
/// <reference path="../geom/Point.ts" />
|
||||
/// <reference path="../math/Vec2Utils.ts" />
|
||||
/// <reference path="../math/Transform.ts" />
|
||||
/// <reference path="../math/TransformUtils.ts" />
|
||||
/// <reference path="Manager.ts" />
|
||||
/// <reference path="joints/Joint.ts" />
|
||||
/// <reference path="Bounds.ts" />
|
||||
/// <reference path="Space.ts" />
|
||||
/// <reference path="shapes/IShape.ts" />
|
||||
/// <reference path="shapes/Triangle.ts" />
|
||||
/// <reference path="shapes/Circle.ts" />
|
||||
/// <reference path="shapes/Box.ts" />
|
||||
/// <reference path="shapes/Poly.ts" />
|
||||
/// <reference path="shapes/Segment.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - Physics - Body
|
||||
* Phaser - Advanced Physics - Body
|
||||
*
|
||||
* Based on the work Ju Hyung Lee started in JS PhyRus.
|
||||
*/
|
||||
|
||||
module Phaser.Physics {
|
||||
|
||||
export class Body {
|
||||
|
||||
constructor(sprite: Phaser.Sprite, type: number) {
|
||||
constructor(sprite: Phaser.Sprite, type: number, x?: number = 0, y?: number = 0, shapeType?: number = 0) {
|
||||
|
||||
this.sprite = sprite;
|
||||
this.game = sprite.game;
|
||||
this.id = Phaser.Physics.Manager.bodyCounter++;
|
||||
this.name = 'body' + this.id;
|
||||
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;
|
||||
|
||||
this._width = sprite.width;
|
||||
this._height = sprite.height;
|
||||
|
||||
|
||||
// Body properties
|
||||
this.gravity = Vec2Utils.clone(this.game.world.physics.gravity);
|
||||
this.bounce = Vec2Utils.clone(this.game.world.physics.bounce);
|
||||
|
||||
this.velocity = new Vec2;
|
||||
this.acceleration = new Vec2;
|
||||
this.drag = Vec2Utils.clone(this.game.world.physics.drag);
|
||||
this.maxVelocity = new Vec2(10000, 10000);
|
||||
if (sprite)
|
||||
{
|
||||
this.sprite = sprite;
|
||||
this.game = sprite.game;
|
||||
this.position = new Phaser.Vec2(Phaser.Physics.Manager.pixelsToMeters(sprite.x), Phaser.Physics.Manager.pixelsToMeters(sprite.y));
|
||||
this.angle = sprite.rotation;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.position = new Phaser.Vec2(Phaser.Physics.Manager.pixelsToMeters(x), Phaser.Physics.Manager.pixelsToMeters(y));
|
||||
this.angle = 0;
|
||||
}
|
||||
|
||||
this.transform = new Phaser.Transform(this.position, this.angle);
|
||||
this.centroid = new Phaser.Vec2;
|
||||
this.velocity = new Phaser.Vec2;
|
||||
this.force = new Phaser.Vec2;
|
||||
this.angularVelocity = 0;
|
||||
this.angularAcceleration = 0;
|
||||
this.angularDrag = 0;
|
||||
this.torque = 0;
|
||||
this.linearDamping = 0;
|
||||
this.angularDamping = 0;
|
||||
this.sleepTime = 0;
|
||||
this.awaked = false;
|
||||
|
||||
this.touching = Types.NONE;
|
||||
this.wasTouching = Types.NONE;
|
||||
this.allowCollisions = Types.ANY;
|
||||
this.shapes = [];
|
||||
this.joints = [];
|
||||
this.jointHash = {};
|
||||
|
||||
this.position = new Vec2(sprite.x + this.bounds.halfWidth, sprite.y + this.bounds.halfHeight);
|
||||
this.oldPosition = new Vec2(sprite.x + this.bounds.halfWidth, sprite.y + this.bounds.halfHeight);
|
||||
this.offset = new Vec2;
|
||||
this.bounds = new Bounds;
|
||||
|
||||
this.allowCollisions = Phaser.Types.ANY;
|
||||
this.fixedRotation = false;
|
||||
|
||||
this.categoryBits = 0x0001;
|
||||
this.maskBits = 0xFFFF;
|
||||
|
||||
this.stepCount = 0;
|
||||
|
||||
if (sprite)
|
||||
{
|
||||
if (shapeType == 0)
|
||||
{
|
||||
this.addBox(0, 0, this.sprite.width, this.sprite.height, 1, 1, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.addCircle(Math.max(this.sprite.width, this.sprite.height) / 2, 0, 0, 1, 1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public toString(): string {
|
||||
return "[{Body (name=" + this.name + " velocity=" + this.velocity.toString() + " angularVelocity: " + this.angularVelocity + ")}]";
|
||||
}
|
||||
|
||||
private _tempVec2: Phaser.Vec2 = new Phaser.Vec2;
|
||||
|
||||
/**
|
||||
* Reference to Phaser.Game
|
||||
*/
|
||||
public game: Game;
|
||||
public game: Phaser.Game;
|
||||
|
||||
/**
|
||||
* Reference to the parent Sprite
|
||||
*/
|
||||
public sprite: Phaser.Sprite;
|
||||
|
||||
/**
|
||||
* The Body ID
|
||||
*/
|
||||
public id: number;
|
||||
|
||||
/**
|
||||
* The Body name
|
||||
*/
|
||||
public name: string;
|
||||
|
||||
/**
|
||||
* The type of Body (disabled, dynamic, static or kinematic)
|
||||
* Disabled = skips all physics operations / tests (default)
|
||||
|
@ -67,243 +118,586 @@ module Phaser.Physics {
|
|||
*/
|
||||
public type: number;
|
||||
|
||||
public gravity: Vec2;
|
||||
public bounce: Vec2;
|
||||
public angle: number;
|
||||
|
||||
public velocity: Vec2;
|
||||
public acceleration: Vec2;
|
||||
public drag: Vec2;
|
||||
public maxVelocity: Vec2;
|
||||
// Local to world transform
|
||||
public transform: Phaser.Transform;
|
||||
|
||||
public angularVelocity: number = 0;
|
||||
public angularAcceleration: number = 0;
|
||||
public angularDrag: number = 0;
|
||||
public maxAngular: number = 10000;
|
||||
// Local center of mass
|
||||
public centroid: Phaser.Vec2;
|
||||
|
||||
/**
|
||||
* Orientation of the object.
|
||||
* @type {number}
|
||||
*/
|
||||
public facing: number;
|
||||
// World position of centroid
|
||||
public position: Phaser.Vec2;
|
||||
|
||||
public touching: number;
|
||||
// Velocity
|
||||
public velocity: Phaser.Vec2;
|
||||
|
||||
// Force
|
||||
public force: Phaser.Vec2;
|
||||
|
||||
// Angular velocity
|
||||
public angularVelocity: number;
|
||||
|
||||
// Torque
|
||||
public torque: number;
|
||||
|
||||
// Linear damping
|
||||
public linearDamping: number;
|
||||
|
||||
// Angular damping
|
||||
public angularDamping: number;
|
||||
|
||||
// Sleep time
|
||||
public sleepTime: number;
|
||||
|
||||
// Awaked
|
||||
public awaked: bool;
|
||||
|
||||
// Allow Collisions
|
||||
public allowCollisions: number;
|
||||
public wasTouching: number;
|
||||
public mass: number = 1;
|
||||
|
||||
public position: Vec2;
|
||||
public oldPosition: Vec2;
|
||||
public offset: Vec2;
|
||||
public bounds: Rectangle;
|
||||
// Shapes
|
||||
public shapes: IShape[] = [];
|
||||
|
||||
// Length of the shapes array
|
||||
public shapesLength: number;
|
||||
|
||||
// Joints
|
||||
public joints: IJoint[] = [];
|
||||
public jointHash = {};
|
||||
|
||||
private _width: number = 0;
|
||||
private _height: number = 0;
|
||||
// Bounds of all shapes
|
||||
public bounds: Bounds;
|
||||
|
||||
public get x(): number {
|
||||
return this.sprite.x + this.offset.x;
|
||||
}
|
||||
public mass: number;
|
||||
public massInverted: number;
|
||||
public inertia: number;
|
||||
public inertiaInverted: number;
|
||||
|
||||
public get y(): number {
|
||||
return this.sprite.y + this.offset.y;
|
||||
}
|
||||
public fixedRotation = false;
|
||||
public categoryBits = 0x0001;
|
||||
public maskBits = 0xFFFF;
|
||||
public stepCount = 0;
|
||||
public space: Space;
|
||||
|
||||
public set width(value: number) {
|
||||
this._width = value;
|
||||
}
|
||||
public duplicate() {
|
||||
|
||||
public set height(value: number) {
|
||||
this._height = value;
|
||||
}
|
||||
console.log('body duplicate called');
|
||||
|
||||
public get width(): number {
|
||||
return this._width * this.sprite.transform.scale.x;
|
||||
}
|
||||
//var body = new Body(this.type, this.transform.t, this.angle);
|
||||
|
||||
//for (var i = 0; i < this.shapes.length; i++)
|
||||
//{
|
||||
// body.addShape(this.shapes[i].duplicate());
|
||||
//}
|
||||
|
||||
public get height(): number {
|
||||
return this._height * this.sprite.transform.scale.y;
|
||||
}
|
||||
//body.resetMassData();
|
||||
|
||||
public preUpdate() {
|
||||
//return body;
|
||||
|
||||
this.oldPosition.copyFrom(this.position);
|
||||
}
|
||||
|
||||
this.bounds.x = this.x;
|
||||
this.bounds.y = this.y;
|
||||
this.bounds.width = this.width;
|
||||
this.bounds.height = this.height;
|
||||
public get isDisabled(): bool {
|
||||
return this.type == Phaser.Types.BODY_DISABLED ? true : false;
|
||||
}
|
||||
|
||||
}
|
||||
public get isStatic(): bool {
|
||||
return this.type == Phaser.Types.BODY_STATIC ? true : 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() {
|
||||
public get isKinetic(): bool {
|
||||
return this.type == Phaser.Types.BODY_KINETIC ? true : false;
|
||||
}
|
||||
|
||||
// if this is all it does maybe move elsewhere? Sprite postUpdate?
|
||||
if (this.type !== Phaser.Types.BODY_DISABLED)
|
||||
public get isDynamic(): bool {
|
||||
return this.type == Phaser.Types.BODY_DYNAMIC ? true : false;
|
||||
}
|
||||
|
||||
public setType(type: number) {
|
||||
|
||||
if (type == this.type)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.force.setTo(0, 0);
|
||||
this.velocity.setTo(0, 0);
|
||||
this.torque = 0;
|
||||
this.angularVelocity = 0;
|
||||
this.type = type;
|
||||
|
||||
this.awake(true);
|
||||
|
||||
}
|
||||
|
||||
public addPoly(verts, elasticity?: number = 1, friction?: number = 1, density?: number = 1): Phaser.Physics.Shapes.Poly {
|
||||
|
||||
var poly: Phaser.Physics.Shapes.Poly = new Phaser.Physics.Shapes.Poly(verts);
|
||||
poly.elasticity = elasticity;
|
||||
poly.friction = friction;
|
||||
poly.density = density;
|
||||
|
||||
this.addShape(poly);
|
||||
this.resetMassData();
|
||||
|
||||
return poly;
|
||||
|
||||
}
|
||||
|
||||
public addTriangle(x1: number, y1: number, x2: number, y2: number, x3: number, y3: number, elasticity?: number = 1, friction?: number = 1, density?: number = 1): Phaser.Physics.Shapes.Triangle {
|
||||
|
||||
var tri: Phaser.Physics.Shapes.Triangle = new Phaser.Physics.Shapes.Triangle(x1, y1, x2, y2, x3, y3);
|
||||
tri.elasticity = elasticity;
|
||||
tri.friction = friction;
|
||||
tri.density = density;
|
||||
|
||||
this.addShape(tri);
|
||||
this.resetMassData();
|
||||
|
||||
return tri;
|
||||
|
||||
}
|
||||
|
||||
public addBox(x: number, y: number, width: number, height: number, elasticity?: number = 1, friction?: number = 1, density?: number = 1): Phaser.Physics.Shapes.Box {
|
||||
|
||||
var box: Phaser.Physics.Shapes.Box = new Phaser.Physics.Shapes.Box(x, y, width, height);
|
||||
box.elasticity = elasticity;
|
||||
box.friction = friction;
|
||||
box.density = density;
|
||||
|
||||
this.addShape(box);
|
||||
this.resetMassData();
|
||||
|
||||
return box;
|
||||
|
||||
}
|
||||
|
||||
public addCircle(radius: number, x?: number = 0, y?: number = 0, elasticity?: number = 1, friction?: number = 1, density?: number = 1): Phaser.Physics.Shapes.Circle {
|
||||
|
||||
var circle: Phaser.Physics.Shapes.Circle = new Phaser.Physics.Shapes.Circle(radius, x, y);
|
||||
circle.elasticity = elasticity;
|
||||
circle.friction = friction;
|
||||
circle.density = density;
|
||||
|
||||
this.addShape(circle);
|
||||
this.resetMassData();
|
||||
|
||||
return circle;
|
||||
|
||||
}
|
||||
|
||||
public addShape(shape) {
|
||||
|
||||
// Check not already part of this body
|
||||
shape.body = this;
|
||||
|
||||
this.shapes.push(shape);
|
||||
|
||||
this.shapesLength = this.shapes.length;
|
||||
|
||||
return shape;
|
||||
|
||||
}
|
||||
|
||||
public removeShape(shape) {
|
||||
|
||||
var index = this.shapes.indexOf(shape);
|
||||
|
||||
if (index != -1)
|
||||
{
|
||||
this.shapes.splice(index, 1);
|
||||
shape.body = undefined;
|
||||
}
|
||||
|
||||
this.shapesLength = this.shapes.length;
|
||||
|
||||
}
|
||||
|
||||
private setMass(mass) {
|
||||
|
||||
this.mass = mass;
|
||||
this.massInverted = mass > 0 ? 1 / mass : 0;
|
||||
|
||||
}
|
||||
|
||||
private setInertia(inertia) {
|
||||
|
||||
this.inertia = inertia;
|
||||
this.inertiaInverted = inertia > 0 ? 1 / inertia : 0;
|
||||
|
||||
}
|
||||
|
||||
public setTransform(pos, angle) {
|
||||
|
||||
// inject the transform into this.position
|
||||
this.transform.setTo(pos, angle);
|
||||
Manager.write('setTransform: ' + this.position.toString());
|
||||
Manager.write('centroid: ' + this.centroid.toString());
|
||||
Phaser.TransformUtils.transform(this.transform, this.centroid, this.position);
|
||||
Manager.write('post setTransform: ' + this.position.toString());
|
||||
//this.position.copyFrom(this.transform.transform(this.centroid));
|
||||
this.angle = angle;
|
||||
|
||||
}
|
||||
|
||||
public syncTransform() {
|
||||
|
||||
Manager.write('syncTransform:');
|
||||
Manager.write('p: ' + this.position.toString());
|
||||
Manager.write('centroid: ' + this.centroid.toString());
|
||||
Manager.write('xf: ' + this.transform.toString());
|
||||
Manager.write('a: ' + this.angle);
|
||||
this.transform.setRotation(this.angle);
|
||||
// OPTIMISE: Creating new vector
|
||||
Phaser.Vec2Utils.subtract(this.position, Phaser.TransformUtils.rotate(this.transform, this.centroid), this.transform.t);
|
||||
Manager.write('--------------------');
|
||||
Manager.write('xf: ' + this.transform.toString());
|
||||
Manager.write('--------------------');
|
||||
|
||||
}
|
||||
|
||||
public getWorldPoint(p:Phaser.Vec2) {
|
||||
// OPTIMISE: Creating new vector
|
||||
return Phaser.TransformUtils.transform(this.transform, p);
|
||||
}
|
||||
|
||||
public getWorldVector(v:Phaser.Vec2) {
|
||||
// OPTIMISE: Creating new vector
|
||||
return Phaser.TransformUtils.rotate(this.transform, v);
|
||||
}
|
||||
|
||||
public getLocalPoint(p:Phaser.Vec2) {
|
||||
// OPTIMISE: Creating new vector
|
||||
return Phaser.TransformUtils.untransform(this.transform, p);
|
||||
}
|
||||
|
||||
public getLocalVector(v:Phaser.Vec2) {
|
||||
// OPTIMISE: Creating new vector
|
||||
return Phaser.TransformUtils.unrotate(this.transform, v);
|
||||
}
|
||||
|
||||
public setFixedRotation(flag) {
|
||||
this.fixedRotation = flag;
|
||||
this.resetMassData();
|
||||
}
|
||||
|
||||
public resetMassData() {
|
||||
|
||||
this.centroid.setTo(0, 0);
|
||||
this.mass = 0;
|
||||
this.massInverted = 0;
|
||||
this.inertia = 0;
|
||||
this.inertiaInverted = 0;
|
||||
|
||||
if (this.isDynamic == false)
|
||||
{
|
||||
Phaser.TransformUtils.transform(this.transform, this.centroid, this.position);
|
||||
//this.position.copyFrom(this.transform.transform(this.centroid));
|
||||
return;
|
||||
}
|
||||
|
||||
var totalMassCentroid = new Phaser.Vec2(0, 0);
|
||||
var totalMass = 0;
|
||||
var totalInertia = 0;
|
||||
|
||||
for (var i = 0; i < this.shapes.length; i++)
|
||||
{
|
||||
var shape = this.shapes[i];
|
||||
var centroid = shape.centroid();
|
||||
var mass = shape.area() * shape.density;
|
||||
var inertia = shape.inertia(mass);
|
||||
|
||||
//console.log('rmd', centroid, shape);
|
||||
|
||||
totalMassCentroid.multiplyAddByScalar(centroid, mass);
|
||||
totalMass += mass;
|
||||
totalInertia += inertia;
|
||||
}
|
||||
|
||||
//this.centroid.copy(vec2.scale(totalMassCentroid, 1 / totalMass));
|
||||
Phaser.Vec2Utils.scale(totalMassCentroid, 1 / totalMass, this.centroid);
|
||||
|
||||
this.setMass(totalMass);
|
||||
|
||||
if (!this.fixedRotation)
|
||||
{
|
||||
this.setInertia(totalInertia - totalMass * Phaser.Vec2Utils.dot(this.centroid, this.centroid));
|
||||
}
|
||||
|
||||
// Move center of mass
|
||||
var oldPosition: Phaser.Vec2 = Phaser.Vec2Utils.clone(this.position);
|
||||
Phaser.TransformUtils.transform(this.transform, this.centroid, this.position);
|
||||
|
||||
// Update center of mass velocity
|
||||
oldPosition.subtract(this.position);
|
||||
this.velocity.multiplyAddByScalar(Phaser.Vec2Utils.perp(oldPosition, oldPosition), this.angularVelocity);
|
||||
|
||||
}
|
||||
|
||||
public resetJointAnchors() {
|
||||
|
||||
for (var i = 0; i < this.joints.length; i++)
|
||||
{
|
||||
var joint = this.joints[i];
|
||||
|
||||
if (!joint)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var anchor1 = joint.getWorldAnchor1();
|
||||
var anchor2 = joint.getWorldAnchor2();
|
||||
|
||||
joint.setWorldAnchor1(anchor1);
|
||||
joint.setWorldAnchor2(anchor2);
|
||||
}
|
||||
}
|
||||
|
||||
public cacheData(source:string = '') {
|
||||
|
||||
Manager.write('cacheData -- start');
|
||||
Manager.write('p: ' + this.position.toString());
|
||||
Manager.write('xf: ' + this.transform.toString());
|
||||
|
||||
this.bounds.clear();
|
||||
|
||||
for (var i = 0; i < this.shapesLength; i++)
|
||||
{
|
||||
var shape: IShape = this.shapes[i];
|
||||
shape.cacheData(this.transform);
|
||||
this.bounds.addBounds(shape.bounds);
|
||||
}
|
||||
|
||||
Manager.write('bounds: ' + this.bounds.toString());
|
||||
|
||||
Manager.write('p: ' + this.position.toString());
|
||||
Manager.write('xf: ' + this.transform.toString());
|
||||
Manager.write('cacheData -- stop');
|
||||
|
||||
}
|
||||
|
||||
public updateVelocity(gravity, dt, damping) {
|
||||
|
||||
Phaser.Vec2Utils.multiplyAdd(gravity, this.force, this.massInverted, this._tempVec2);
|
||||
Phaser.Vec2Utils.multiplyAdd(this.velocity, this._tempVec2, dt, this.velocity);
|
||||
|
||||
this.angularVelocity = this.angularVelocity + this.torque * this.inertiaInverted * dt;
|
||||
|
||||
// Apply damping.
|
||||
// ODE: dv/dt + c * v = 0
|
||||
// Solution: v(t) = v0 * exp(-c * t)
|
||||
// Time step: v(t + dt) = v0 * exp(-c * (t + dt)) = v0 * exp(-c * t) * exp(-c * dt) = v * exp(-c * dt)
|
||||
// v2 = exp(-c * dt) * v1
|
||||
// Taylor expansion:
|
||||
// v2 = (1.0f - c * dt) * v1
|
||||
this.velocity.scale(this.clamp(1 - dt * (damping + this.linearDamping), 0, 1));
|
||||
this.angularVelocity *= this.clamp(1 - dt * (damping + this.angularDamping), 0, 1);
|
||||
|
||||
this.force.setTo(0, 0);
|
||||
this.torque = 0;
|
||||
|
||||
}
|
||||
|
||||
public inContact(body2: Body): bool {
|
||||
|
||||
if (!body2 || this.stepCount == body2.stepCount)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(this.isAwake && this.isStatic == false) && !(body2.isAwake && body2.isStatic == false))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.isCollidable(body2) == false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!this.bounds.intersectsBounds(body2.bounds))
|
||||
{
|
||||
this.game.world.physics.updateMotion(this);
|
||||
|
||||
this.wasTouching = this.touching;
|
||||
this.touching = Phaser.Types.NONE;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
this.position.setTo(this.x, this.y);
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public clamp(v, min, max) {
|
||||
return v < min ? min : (v > max ? max : v);
|
||||
}
|
||||
|
||||
public get hullWidth(): number {
|
||||
public updatePosition(dt:number) {
|
||||
|
||||
if (this.deltaX > 0)
|
||||
this.position.add(Phaser.Vec2Utils.scale(this.velocity, dt, this._tempVec2));
|
||||
|
||||
this.angle += this.angularVelocity * dt;
|
||||
|
||||
if (this.sprite)
|
||||
{
|
||||
return this.bounds.width + this.deltaX;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.bounds.width - this.deltaX;
|
||||
this.sprite.x = this.position.x * 50;
|
||||
this.sprite.y = this.position.y * 50;
|
||||
// Obey fixed rotation?
|
||||
this.sprite.rotation = this.game.math.radiansToDegrees(this.angle);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public get hullHeight(): number {
|
||||
public resetForce() {
|
||||
this.force.setTo(0, 0);
|
||||
this.torque = 0;
|
||||
}
|
||||
|
||||
if (this.deltaY > 0)
|
||||
{
|
||||
return this.bounds.height + this.deltaY;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.bounds.height - this.deltaY;
|
||||
}
|
||||
public applyForce(force:Phaser.Vec2, p:Phaser.Vec2) {
|
||||
|
||||
}
|
||||
if (this.isDynamic == false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public get hullX(): number {
|
||||
if (this.isAwake == false)
|
||||
{
|
||||
this.awake(true);
|
||||
}
|
||||
|
||||
if (this.position.x < this.oldPosition.x)
|
||||
{
|
||||
return this.position.x;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.oldPosition.x;
|
||||
}
|
||||
this.force.add(force);
|
||||
|
||||
}
|
||||
Phaser.Vec2Utils.subtract(p, this.position, this._tempVec2);
|
||||
|
||||
public get hullY(): number {
|
||||
this.torque += Phaser.Vec2Utils.cross(this._tempVec2, force);
|
||||
|
||||
if (this.position.y < this.oldPosition.y)
|
||||
{
|
||||
return this.position.y;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.oldPosition.y;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
public applyForceToCenter(force:Phaser.Vec2) {
|
||||
|
||||
public get deltaXAbs(): number {
|
||||
return (this.deltaX > 0 ? this.deltaX : -this.deltaX);
|
||||
}
|
||||
if (this.isDynamic == false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public get deltaYAbs(): number {
|
||||
return (this.deltaY > 0 ? this.deltaY : -this.deltaY);
|
||||
}
|
||||
if (this.isAwake == false)
|
||||
{
|
||||
this.awake(true);
|
||||
}
|
||||
|
||||
public get deltaX(): number {
|
||||
return this.position.x - this.oldPosition.x;
|
||||
}
|
||||
this.force.add(force);
|
||||
|
||||
public get deltaY(): number {
|
||||
return this.position.y - this.oldPosition.y;
|
||||
}
|
||||
}
|
||||
|
||||
public applyTorque(torque:number) {
|
||||
|
||||
if (this.isDynamic == false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.isAwake == false)
|
||||
{
|
||||
this.awake(true);
|
||||
}
|
||||
|
||||
this.torque += torque;
|
||||
|
||||
}
|
||||
|
||||
public applyLinearImpulse(impulse:Phaser.Vec2, p:Phaser.Vec2) {
|
||||
|
||||
if (this.isDynamic == false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.isAwake == false)
|
||||
{
|
||||
this.awake(true);
|
||||
}
|
||||
|
||||
this.velocity.multiplyAddByScalar(impulse, this.massInverted);
|
||||
|
||||
// MOVE THESE TO A UTIL
|
||||
Phaser.Vec2Utils.subtract(p, this.position, this._tempVec2);
|
||||
|
||||
public render(context:CanvasRenderingContext2D) {
|
||||
this.angularVelocity += Phaser.Vec2Utils.cross(this._tempVec2, impulse) * this.inertiaInverted;
|
||||
|
||||
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);
|
||||
public applyAngularImpulse(impulse: number) {
|
||||
|
||||
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.isDynamic == false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
if (this.isAwake == false)
|
||||
{
|
||||
this.awake(true);
|
||||
}
|
||||
|
||||
}
|
||||
this.angularVelocity += impulse * this.inertiaInverted;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)') {
|
||||
public kineticEnergy() {
|
||||
|
||||
this.sprite.texture.context.fillStyle = color;
|
||||
this.sprite.texture.context.fillText('Sprite: (' + this.sprite.width + ' x ' + this.sprite.height + ')', x, y);
|
||||
//this.sprite.texture.context.fillText('x: ' + this._sprite.frameBounds.x.toFixed(1) + ' y: ' + this._sprite.frameBounds.y.toFixed(1) + ' rotation: ' + this._sprite.rotation.toFixed(1), x, y + 14);
|
||||
this.sprite.texture.context.fillText('x: ' + this.bounds.x.toFixed(1) + ' y: ' + this.bounds.y.toFixed(1) + ' rotation: ' + this.sprite.transform.rotation.toFixed(0), x, y + 14);
|
||||
this.sprite.texture.context.fillText('vx: ' + this.velocity.x.toFixed(1) + ' vy: ' + this.velocity.y.toFixed(1), x, y + 28);
|
||||
this.sprite.texture.context.fillText('acx: ' + this.acceleration.x.toFixed(1) + ' acy: ' + this.acceleration.y.toFixed(1), x, y + 42);
|
||||
this.sprite.texture.context.fillText('angVx: ' + this.angularVelocity.toFixed(1) + ' angAc: ' + this.angularAcceleration.toFixed(1), x, y + 56);
|
||||
var vsq = this.velocity.dot(this.velocity);
|
||||
var wsq = this.angularVelocity * this.angularVelocity;
|
||||
|
||||
return 0.5 * (this.mass * vsq + this.inertia * wsq);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public get isAwake(): bool {
|
||||
return this.awaked;
|
||||
}
|
||||
|
||||
public awake(flag) {
|
||||
|
||||
this.awaked = flag;
|
||||
|
||||
if (flag)
|
||||
{
|
||||
this.sleepTime = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.velocity.setTo(0, 0);
|
||||
this.angularVelocity = 0;
|
||||
this.force.setTo(0, 0);
|
||||
this.torque = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public isCollidable(other:Body) {
|
||||
|
||||
if (this == other)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.isDynamic == false && other.isDynamic == false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(this.maskBits & other.categoryBits) || !(other.maskBits & this.categoryBits))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (var i = 0; i < this.joints.length; i++)
|
||||
{
|
||||
var joint = this.joints[i];
|
||||
|
||||
if (!this.joints[i] || (!this.joints[i].collideConnected && other.jointHash[this.joints[i].id] != undefined))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/// <reference path="../../Game.ts" />
|
||||
/// <reference path="../../math/Vec2.ts" />
|
||||
/// <reference path="../../math/Vec2Utils.ts" />
|
||||
/// <reference path="../Game.ts" />
|
||||
/// <reference path="../math/Vec2.ts" />
|
||||
/// <reference path="../math/Vec2Utils.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - 2D AABB
|
||||
|
@ -8,7 +8,7 @@
|
|||
* A 2D AABB object
|
||||
*/
|
||||
|
||||
module Phaser.Physics.Advanced {
|
||||
module Phaser.Physics {
|
||||
|
||||
export class Bounds {
|
||||
|
||||
|
@ -72,19 +72,27 @@ module Phaser.Physics.Advanced {
|
|||
}
|
||||
|
||||
public get x(): number {
|
||||
return Phaser.Physics.Advanced.Manager.metersToPixels(this.mins.x);
|
||||
return Phaser.Physics.Manager.metersToPixels(this.mins.x);
|
||||
}
|
||||
|
||||
public get y(): number {
|
||||
return Phaser.Physics.Advanced.Manager.metersToPixels(this.mins.y);
|
||||
return Phaser.Physics.Manager.metersToPixels(this.mins.y);
|
||||
}
|
||||
|
||||
public get width(): number {
|
||||
return Phaser.Physics.Advanced.Manager.metersToPixels(this.maxs.x - this.mins.x);
|
||||
return Phaser.Physics.Manager.metersToPixels(this.maxs.x - this.mins.x);
|
||||
}
|
||||
|
||||
public get height(): number {
|
||||
return Phaser.Physics.Advanced.Manager.metersToPixels(this.maxs.y - this.mins.y);
|
||||
return Phaser.Physics.Manager.metersToPixels(this.maxs.y - this.mins.y);
|
||||
}
|
||||
|
||||
public get right(): number {
|
||||
return this.x + this.width;
|
||||
}
|
||||
|
||||
public get bottom(): number {
|
||||
return this.y + this.height;
|
||||
}
|
||||
|
||||
public isEmpty(): bool {
|
||||
|
@ -125,11 +133,13 @@ module Phaser.Physics.Advanced {
|
|||
return this;
|
||||
}
|
||||
|
||||
public addBounds2(mins, maxs) {
|
||||
public addBounds2(mins, maxs): Bounds {
|
||||
|
||||
if (this.mins.x > mins.x) this.mins.x = mins.x;
|
||||
if (this.maxs.x < maxs.x) this.maxs.x = maxs.x;
|
||||
if (this.mins.y > mins.y) this.mins.y = mins.y;
|
||||
if (this.maxs.y < maxs.y) this.maxs.y = maxs.y;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
/// <reference path="../../math/Vec2.ts" />
|
||||
/// <reference path="../../geom/Point.ts" />
|
||||
/// <reference path="../../math/Vec2Utils.ts" />
|
||||
/// <reference path="../math/Vec2.ts" />
|
||||
/// <reference path="../geom/Point.ts" />
|
||||
/// <reference path="../math/Vec2Utils.ts" />
|
||||
/// <reference path="shapes/Shape.ts" />
|
||||
/// <reference path="shapes/Circle.ts" />
|
||||
/// <reference path="shapes/Poly.ts" />
|
||||
|
@ -15,13 +15,10 @@
|
|||
* Based on the work Ju Hyung Lee started in JS PhyRus.
|
||||
*/
|
||||
|
||||
module Phaser.Physics.Advanced {
|
||||
module Phaser.Physics {
|
||||
|
||||
export class Collision {
|
||||
|
||||
constructor() {
|
||||
}
|
||||
|
||||
public collide(a, b, contacts: Contact[]) {
|
||||
|
||||
// Circle (a is the circle)
|
||||
|
@ -114,11 +111,11 @@ module Phaser.Physics.Advanced {
|
|||
|
||||
}
|
||||
|
||||
public circle2Circle(circ1: Phaser.Physics.Advanced.Shapes.Circle, circ2: Phaser.Physics.Advanced.Shapes.Circle, contactArr: Contact[]) {
|
||||
public circle2Circle(circ1: Phaser.Physics.Shapes.Circle, circ2: Phaser.Physics.Shapes.Circle, contactArr: Contact[]) {
|
||||
return this._circle2Circle(circ1.tc, circ1.radius, circ2.tc, circ2.radius, contactArr);
|
||||
}
|
||||
|
||||
public circle2Segment(circ: Phaser.Physics.Advanced.Shapes.Circle, seg: Phaser.Physics.Advanced.Shapes.Segment, contactArr: Contact[]) {
|
||||
public circle2Segment(circ: Phaser.Physics.Shapes.Circle, seg: Phaser.Physics.Shapes.Segment, contactArr: Contact[]) {
|
||||
|
||||
var rsum = circ.radius + seg.radius;
|
||||
|
||||
|
@ -179,7 +176,7 @@ module Phaser.Physics.Advanced {
|
|||
|
||||
}
|
||||
|
||||
public circle2Poly(circ: Phaser.Physics.Advanced.Shapes.Circle, poly: Phaser.Physics.Advanced.Shapes.Poly, contactArr: Contact[]) {
|
||||
public circle2Poly(circ: Phaser.Physics.Shapes.Circle, poly: Phaser.Physics.Shapes.Poly, contactArr: Contact[]) {
|
||||
|
||||
var minDist = -999999;
|
||||
var minIdx = -1;
|
||||
|
@ -230,7 +227,7 @@ module Phaser.Physics.Advanced {
|
|||
|
||||
}
|
||||
|
||||
public segmentPointDistanceSq(seg: Phaser.Physics.Advanced.Shapes.Segment, p) {
|
||||
public segmentPointDistanceSq(seg: Phaser.Physics.Shapes.Segment, p) {
|
||||
|
||||
var w: Phaser.Vec2 = new Phaser.Vec2;
|
||||
var d: Phaser.Vec2 = new Phaser.Vec2;
|
||||
|
@ -259,7 +256,7 @@ module Phaser.Physics.Advanced {
|
|||
}
|
||||
|
||||
// FIXME and optimise me lots!!!
|
||||
public segment2Segment(seg1: Phaser.Physics.Advanced.Shapes.Segment, seg2: Phaser.Physics.Advanced.Shapes.Segment, contactArr: Contact[]) {
|
||||
public segment2Segment(seg1: Phaser.Physics.Shapes.Segment, seg2: Phaser.Physics.Shapes.Segment, contactArr: Contact[]) {
|
||||
|
||||
var d = [];
|
||||
d[0] = this.segmentPointDistanceSq(seg1, seg2.ta);
|
||||
|
@ -307,7 +304,7 @@ module Phaser.Physics.Advanced {
|
|||
}
|
||||
|
||||
// Identify vertexes that have penetrated the segment.
|
||||
public findPointsBehindSeg(contactArr: Contact[], seg: Phaser.Physics.Advanced.Shapes.Segment, poly: Phaser.Physics.Advanced.Shapes.Poly, dist: number, coef: number) {
|
||||
public findPointsBehindSeg(contactArr: Contact[], seg: Phaser.Physics.Shapes.Segment, poly: Phaser.Physics.Shapes.Poly, dist: number, coef: number) {
|
||||
|
||||
var dta = Phaser.Vec2Utils.cross(seg.tn, seg.ta);
|
||||
var dtb = Phaser.Vec2Utils.cross(seg.tn, seg.tb);
|
||||
|
@ -332,7 +329,7 @@ module Phaser.Physics.Advanced {
|
|||
}
|
||||
}
|
||||
|
||||
public segment2Poly(seg: Phaser.Physics.Advanced.Shapes.Segment, poly: Phaser.Physics.Advanced.Shapes.Poly, contactArr: Contact[]) {
|
||||
public segment2Poly(seg: Phaser.Physics.Shapes.Segment, poly: Phaser.Physics.Shapes.Poly, contactArr: Contact[]) {
|
||||
|
||||
var seg_td = Phaser.Vec2Utils.dot(seg.tn, seg.ta);
|
||||
var seg_d1 = poly.distanceOnPlane(seg.tn, seg_td) - seg.radius;
|
||||
|
@ -442,7 +439,7 @@ module Phaser.Physics.Advanced {
|
|||
}
|
||||
|
||||
// Find the minimum separating axis for the given poly and plane list.
|
||||
public findMSA(poly: Phaser.Physics.Advanced.Shapes.Poly, planes: Phaser.Physics.Advanced.Plane[], num: number) {
|
||||
public findMSA(poly: Phaser.Physics.Shapes.Poly, planes: Phaser.Physics.Plane[], num: number) {
|
||||
|
||||
var min_dist: number = -999999;
|
||||
var min_index: number = -1;
|
||||
|
@ -468,7 +465,7 @@ module Phaser.Physics.Advanced {
|
|||
|
||||
}
|
||||
|
||||
public findVertsFallback(contactArr: Contact[], poly1: Phaser.Physics.Advanced.Shapes.Poly, poly2: Phaser.Physics.Advanced.Shapes.Poly, n, dist: number) {
|
||||
public findVertsFallback(contactArr: Contact[], poly1: Phaser.Physics.Shapes.Poly, poly2: Phaser.Physics.Shapes.Poly, n, dist: number) {
|
||||
|
||||
var num = 0;
|
||||
|
||||
|
@ -499,7 +496,7 @@ module Phaser.Physics.Advanced {
|
|||
}
|
||||
|
||||
// Find the overlapped vertices.
|
||||
public findVerts(contactArr: Contact[], poly1: Phaser.Physics.Advanced.Shapes.Poly, poly2: Phaser.Physics.Advanced.Shapes.Poly, n, dist: number) {
|
||||
public findVerts(contactArr: Contact[], poly1: Phaser.Physics.Shapes.Poly, poly2: Phaser.Physics.Shapes.Poly, n, dist: number) {
|
||||
|
||||
var num = 0;
|
||||
|
||||
|
@ -529,7 +526,7 @@ module Phaser.Physics.Advanced {
|
|||
|
||||
}
|
||||
|
||||
public poly2Poly(poly1: Phaser.Physics.Advanced.Shapes.Poly, poly2: Phaser.Physics.Advanced.Shapes.Poly, contactArr: Contact[]) {
|
||||
public poly2Poly(poly1: Phaser.Physics.Shapes.Poly, poly2: Phaser.Physics.Shapes.Poly, contactArr: Contact[]) {
|
||||
|
||||
var msa1 = this.findMSA(poly2, poly1.tplanes, poly1.verts.length);
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/// <reference path="../../math/Vec2.ts" />
|
||||
/// <reference path="../../math/Vec2Utils.ts" />
|
||||
/// <reference path="../math/Vec2.ts" />
|
||||
/// <reference path="../math/Vec2Utils.ts" />
|
||||
/// <reference path="Manager.ts" />
|
||||
/// <reference path="Body.ts" />
|
||||
/// <reference path="shapes/Shape.ts" />
|
||||
|
@ -10,7 +10,7 @@
|
|||
* Based on the work Ju Hyung Lee started in JS PhyRus.
|
||||
*/
|
||||
|
||||
module Phaser.Physics.Advanced {
|
||||
module Phaser.Physics {
|
||||
|
||||
export class Contact {
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
/// <reference path="../../math/Vec2.ts" />
|
||||
/// <reference path="../../geom/Point.ts" />
|
||||
/// <reference path="../../math/Vec2Utils.ts" />
|
||||
/// <reference path="../math/Vec2.ts" />
|
||||
/// <reference path="../geom/Point.ts" />
|
||||
/// <reference path="../math/Vec2Utils.ts" />
|
||||
/// <reference path="Manager.ts" />
|
||||
/// <reference path="Body.ts" />
|
||||
/// <reference path="shapes/Shape.ts" />
|
||||
|
@ -32,7 +32,7 @@
|
|||
// NOTE: lambda is an impulse in constraint space.
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
|
||||
module Phaser.Physics.Advanced {
|
||||
module Phaser.Physics {
|
||||
|
||||
export class ContactSolver {
|
||||
|
|
@ -1,15 +1,15 @@
|
|||
/// <reference path="../../Game.ts" />
|
||||
/// <reference path="../Game.ts" />
|
||||
/// <reference path="Body.ts" />
|
||||
/// <reference path="joints/Joint.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - Advanced Physics Manager
|
||||
* Phaser - Physics Manager
|
||||
*
|
||||
* Your game only has one PhysicsManager instance and it's responsible for looking after, creating and colliding
|
||||
* all of the physics objects in the world.
|
||||
* The Physics Manager is responsible for looking after, creating and colliding
|
||||
* all of the physics bodies and joints in the world.
|
||||
*/
|
||||
|
||||
module Phaser.Physics.Advanced {
|
||||
module Phaser.Physics {
|
||||
|
||||
export class Manager {
|
||||
|
||||
|
@ -17,7 +17,9 @@ module Phaser.Physics.Advanced {
|
|||
|
||||
this.game = game;
|
||||
|
||||
this.space = new Space();
|
||||
this.gravity = new Phaser.Vec2;
|
||||
|
||||
this.space = new Space(this);
|
||||
|
||||
Manager.collision = new Collision();
|
||||
|
||||
|
@ -31,7 +33,7 @@ module Phaser.Physics.Advanced {
|
|||
public static debug: HTMLTextAreaElement;
|
||||
|
||||
public static clear() {
|
||||
Manager.debug.textContent = "";
|
||||
//Manager.debug.textContent = "";
|
||||
Manager.log = [];
|
||||
}
|
||||
|
||||
|
@ -52,6 +54,7 @@ module Phaser.Physics.Advanced {
|
|||
|
||||
public static dump(phase: string, body: Body) {
|
||||
|
||||
/*
|
||||
var s = "\n\nPhase: " + phase + "\n";
|
||||
s += "Position: " + body.position.toString() + "\n";
|
||||
s += "Velocity: " + body.velocity.toString() + "\n";
|
||||
|
@ -78,6 +81,7 @@ module Phaser.Physics.Advanced {
|
|||
s += "TPlane 3: " + body.shapes[0].tplanes[3].normal.toString() + "\n";
|
||||
|
||||
Manager.log.push(s);
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
|
@ -98,9 +102,9 @@ module Phaser.Physics.Advanced {
|
|||
public static JOINT_TYPE_MOUSE: number = 7;
|
||||
|
||||
public static JOINT_LINEAR_SLOP: number = 0.0008;
|
||||
public static JOINT_ANGULAR_SLOP: number = 2 * Phaser.GameMath.DEG_TO_RAD;
|
||||
public static JOINT_ANGULAR_SLOP: number = 2 * 0.017453292519943294444444444444444;
|
||||
public static JOINT_MAX_LINEAR_CORRECTION: number = 0.5;
|
||||
public static JOINT_MAX_ANGULAR_CORRECTION: number = 8 * Phaser.GameMath.DEG_TO_RAD;
|
||||
public static JOINT_MAX_ANGULAR_CORRECTION: number = 8 * 0.017453292519943294444444444444444;
|
||||
|
||||
public static JOINT_LIMIT_STATE_INACTIVE: number = 0;
|
||||
public static JOINT_LIMIT_STATE_AT_LOWER: number = 1;
|
||||
|
@ -125,13 +129,15 @@ module Phaser.Physics.Advanced {
|
|||
//public step: bool = false; // step through the simulation (i.e. per click)
|
||||
public velocityIterations: number = 8;
|
||||
public positionIterations: number = 4;
|
||||
//public velocityIterations: number = 1;
|
||||
//public positionIterations: number = 1;
|
||||
public allowSleep: bool = true;
|
||||
public warmStarting: bool = true;
|
||||
|
||||
public gravity: Phaser.Vec2;
|
||||
|
||||
|
||||
public update() {
|
||||
|
||||
// Get these from Phaser.Time instead
|
||||
var time = Date.now();
|
||||
var frameTime = (time - this.lastTime) / 1000;
|
||||
this.lastTime = time;
|
||||
|
@ -170,18 +176,28 @@ module Phaser.Physics.Advanced {
|
|||
{
|
||||
this.timeDelta = 0;
|
||||
}
|
||||
|
||||
//if (sceneIndex < demoArr.length)
|
||||
//{
|
||||
// demo = demoArr[sceneIndex];
|
||||
// demo.runFrame();
|
||||
//}
|
||||
}
|
||||
|
||||
//frameCount++;
|
||||
|
||||
}
|
||||
|
||||
public addBody(body: Body) {
|
||||
this.space.addBody(body);
|
||||
}
|
||||
|
||||
public removeBody(body: Body) {
|
||||
this.space.removeBody(body);
|
||||
}
|
||||
|
||||
public addJoint(joint: IJoint) {
|
||||
this.space.addJoint(joint);
|
||||
}
|
||||
|
||||
public removeJoint(joint: IJoint) {
|
||||
this.space.removeJoint(joint);
|
||||
}
|
||||
|
||||
public pixelsToMeters(value: number): number {
|
||||
return value * 0.02;
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -1,5 +1,5 @@
|
|||
/// <reference path="../../math/Vec2.ts" />
|
||||
/// <reference path="../../math/Vec2Utils.ts" />
|
||||
/// <reference path="../math/Vec2.ts" />
|
||||
/// <reference path="../math/Vec2Utils.ts" />
|
||||
/// <reference path="Manager.ts" />
|
||||
/// <reference path="Body.ts" />
|
||||
|
||||
|
@ -9,7 +9,7 @@
|
|||
* Based on the work Ju Hyung Lee started in JS PhyRus.
|
||||
*/
|
||||
|
||||
module Phaser.Physics.Advanced {
|
||||
module Phaser.Physics {
|
||||
|
||||
export class Plane {
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/// <reference path="../../math/Vec2.ts" />
|
||||
/// <reference path="../../math/Vec2Utils.ts" />
|
||||
/// <reference path="../math/Vec2.ts" />
|
||||
/// <reference path="../math/Vec2Utils.ts" />
|
||||
/// <reference path="Manager.ts" />
|
||||
/// <reference path="Body.ts" />
|
||||
/// <reference path="shapes/Shape.ts" />
|
||||
|
@ -14,39 +14,71 @@
|
|||
* Based on the work Ju Hyung Lee started in JS PhyRus.
|
||||
*/
|
||||
|
||||
module Phaser.Physics.Advanced {
|
||||
module Phaser.Physics {
|
||||
|
||||
export class Space {
|
||||
|
||||
constructor() {
|
||||
constructor(manager: Phaser.Physics.Manager) {
|
||||
|
||||
this.bodyArr = [];
|
||||
this._manager = manager;
|
||||
|
||||
this.bodies = [];
|
||||
this.bodyHash = {};
|
||||
|
||||
this.jointArr = [];
|
||||
this.joints = [];
|
||||
this.jointHash = {};
|
||||
|
||||
this.numContacts = 0;
|
||||
this.contactSolvers = [];
|
||||
|
||||
//this.postSolve(arb) { };
|
||||
|
||||
this.gravity = new Phaser.Vec2(0, 10);
|
||||
this.gravity = this._manager.gravity;
|
||||
this.damping = 0;
|
||||
|
||||
this._linTolSqr = Space.SLEEP_LINEAR_TOLERANCE * Space.SLEEP_LINEAR_TOLERANCE;
|
||||
this._angTolSqr = Space.SLEEP_ANGULAR_TOLERANCE * Space.SLEEP_ANGULAR_TOLERANCE;
|
||||
|
||||
}
|
||||
|
||||
private _manager: Phaser.Physics.Manager;
|
||||
|
||||
// Delta Timer
|
||||
private _delta: number;
|
||||
private _deltaInv: number;
|
||||
|
||||
// Body array length
|
||||
private _bl: number;
|
||||
|
||||
// Joints array length
|
||||
private _jl: number;
|
||||
|
||||
// Contact Solvers array length
|
||||
private _cl: number;
|
||||
|
||||
private _linTolSqr: number;
|
||||
private _angTolSqr: number;
|
||||
|
||||
// Minimum sleep time (used in the sleep process solver)
|
||||
private _minSleepTime: number;
|
||||
|
||||
private _positionSolved: bool;
|
||||
|
||||
private _shape1: IShape;
|
||||
private _shape2: IShape;
|
||||
private _contactsOk: bool;
|
||||
private _jointsOk: bool;
|
||||
|
||||
private bodyHash;
|
||||
private jointHash;
|
||||
|
||||
public static TIME_TO_SLEEP = 0.5;
|
||||
public static SLEEP_LINEAR_TOLERANCE = 0.5;
|
||||
public static SLEEP_ANGULAR_TOLERANCE = 2 * Phaser.GameMath.DEG_TO_RAD;
|
||||
public static SLEEP_ANGULAR_TOLERANCE = 2 * 0.017453292519943294444444444444444;
|
||||
|
||||
public bodyArr: Body[];
|
||||
public bodyHash;
|
||||
public jointArr: IJoint[];
|
||||
public jointHash;
|
||||
public bodies: Body[];
|
||||
public joints: IJoint[];
|
||||
public numContacts: number;
|
||||
public contactSolvers: ContactSolver[];
|
||||
public postSolve;
|
||||
public postSolve = null;
|
||||
public gravity: Phaser.Vec2;
|
||||
public damping: number;
|
||||
public stepCount: number = 0;
|
||||
|
@ -57,18 +89,18 @@ module Phaser.Physics.Advanced {
|
|||
Manager.bodyCounter = 0;
|
||||
Manager.jointCounter = 0;
|
||||
|
||||
for (var i = 0; i < this.bodyArr.length; i++)
|
||||
for (var i = 0; i < this.bodies.length; i++)
|
||||
{
|
||||
if (this.bodyArr[i])
|
||||
if (this.bodies[i])
|
||||
{
|
||||
this.removeBody(this.bodyArr[i]);
|
||||
this.removeBody(this.bodies[i]);
|
||||
}
|
||||
}
|
||||
|
||||
this.bodyArr = [];
|
||||
this.bodies = [];
|
||||
this.bodyHash = {};
|
||||
|
||||
this.jointArr = [];
|
||||
this.joints = [];
|
||||
this.jointHash = {};
|
||||
|
||||
this.contactSolvers = [];
|
||||
|
@ -84,7 +116,7 @@ module Phaser.Physics.Advanced {
|
|||
return;
|
||||
}
|
||||
|
||||
var index = this.bodyArr.push(body) - 1;
|
||||
var index = this.bodies.push(body) - 1;
|
||||
this.bodyHash[body.id] = index;
|
||||
|
||||
body.awake(true);
|
||||
|
@ -100,7 +132,7 @@ module Phaser.Physics.Advanced {
|
|||
return;
|
||||
}
|
||||
|
||||
// Remove linked joint
|
||||
// Remove linked joints
|
||||
for (var i = 0; i < body.joints.length; i++)
|
||||
{
|
||||
if (body.joints[i])
|
||||
|
@ -113,7 +145,7 @@ module Phaser.Physics.Advanced {
|
|||
|
||||
var index = this.bodyHash[body.id];
|
||||
delete this.bodyHash[body.id];
|
||||
delete this.bodyArr[index];
|
||||
delete this.bodies[index];
|
||||
|
||||
}
|
||||
|
||||
|
@ -127,7 +159,7 @@ module Phaser.Physics.Advanced {
|
|||
joint.body1.awake(true);
|
||||
joint.body2.awake(true);
|
||||
|
||||
var index = this.jointArr.push(joint) - 1;
|
||||
var index = this.joints.push(joint) - 1;
|
||||
this.jointHash[joint.id] = index;
|
||||
|
||||
var index = joint.body1.joints.push(joint) - 1;
|
||||
|
@ -158,7 +190,7 @@ module Phaser.Physics.Advanced {
|
|||
|
||||
var index = this.jointHash[joint.id];
|
||||
delete this.jointHash[joint.id];
|
||||
delete this.jointArr[index];
|
||||
delete this.joints[index];
|
||||
|
||||
}
|
||||
|
||||
|
@ -166,9 +198,9 @@ module Phaser.Physics.Advanced {
|
|||
|
||||
var firstShape;
|
||||
|
||||
for (var i = 0; i < this.bodyArr.length; i++)
|
||||
for (var i = 0; i < this.bodies.length; i++)
|
||||
{
|
||||
var body = this.bodyArr[i];
|
||||
var body = this.bodies[i];
|
||||
|
||||
if (!body)
|
||||
{
|
||||
|
@ -206,9 +238,9 @@ module Phaser.Physics.Advanced {
|
|||
|
||||
var firstBody;
|
||||
|
||||
for (var i = 0; i < this.bodyArr.length; i++)
|
||||
for (var i = 0; i < this.bodies.length; i++)
|
||||
{
|
||||
var body = this.bodyArr[i];
|
||||
var body = this.bodies[i];
|
||||
|
||||
if (!body)
|
||||
{
|
||||
|
@ -245,14 +277,14 @@ module Phaser.Physics.Advanced {
|
|||
|
||||
}
|
||||
|
||||
// TODO: Replace this function to shape hashing
|
||||
public shapeById(id) {
|
||||
|
||||
var shape;
|
||||
|
||||
for (var i = 0; i < this.bodyArr.length; i++)
|
||||
for (var i = 0; i < this.bodies.length; i++)
|
||||
{
|
||||
var body = this.bodyArr[i];
|
||||
var body: Body = this.bodies[i];
|
||||
|
||||
if (!body)
|
||||
{
|
||||
continue;
|
||||
|
@ -276,7 +308,7 @@ module Phaser.Physics.Advanced {
|
|||
|
||||
if (index != undefined)
|
||||
{
|
||||
return this.jointArr[index];
|
||||
return this.joints[index];
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@ -288,9 +320,9 @@ module Phaser.Physics.Advanced {
|
|||
|
||||
refVertexId = refVertexId || -1;
|
||||
|
||||
for (var i = 0; i < this.bodyArr.length; i++)
|
||||
for (var i = 0; i < this.bodies.length; i++)
|
||||
{
|
||||
var body = this.bodyArr[i];
|
||||
var body = this.bodies[i];
|
||||
|
||||
if (!body)
|
||||
{
|
||||
|
@ -334,9 +366,9 @@ module Phaser.Physics.Advanced {
|
|||
|
||||
refEdgeId = refEdgeId || -1;
|
||||
|
||||
for (var i = 0; i < this.bodyArr.length; i++)
|
||||
for (var i = 0; i < this.bodies.length; i++)
|
||||
{
|
||||
var body = this.bodyArr[i];
|
||||
var body = this.bodies[i];
|
||||
|
||||
if (!body)
|
||||
{
|
||||
|
@ -387,9 +419,9 @@ module Phaser.Physics.Advanced {
|
|||
|
||||
refJointId = refJointId || -1;
|
||||
|
||||
for (var i = 0; i < this.jointArr.length; i++)
|
||||
for (var i = 0; i < this.joints.length; i++)
|
||||
{
|
||||
var joint = this.jointArr[i];
|
||||
var joint = this.joints[i];
|
||||
|
||||
if (!joint)
|
||||
{
|
||||
|
@ -429,13 +461,13 @@ module Phaser.Physics.Advanced {
|
|||
return firstJointId;
|
||||
}
|
||||
|
||||
public findContactSolver(shape1, shape2) {
|
||||
private findContactSolver(shape1:IShape, shape2:IShape):ContactSolver {
|
||||
|
||||
Manager.write('findContactSolver. Length: ' + this.contactSolvers.length);
|
||||
Manager.write('findContactSolver. Length: ' + this._cl);
|
||||
|
||||
for (var i = 0; i < this.contactSolvers.length; i++)
|
||||
for (var i = 0; i < this._cl; i++)
|
||||
{
|
||||
var contactSolver = this.contactSolvers[i];
|
||||
var contactSolver: ContactSolver = this.contactSolvers[i];
|
||||
|
||||
if (shape1 == contactSolver.shape1 && shape2 == contactSolver.shape2)
|
||||
{
|
||||
|
@ -444,363 +476,346 @@ module Phaser.Physics.Advanced {
|
|||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
public genTemporalContactSolvers() {
|
||||
private genTemporalContactSolvers() {
|
||||
|
||||
Manager.write('genTemporalContactSolvers');
|
||||
|
||||
var newContactSolverArr = [];
|
||||
var bl: number = this.bodyArr.length;
|
||||
|
||||
this._cl = 0;
|
||||
this.contactSolvers.length = 0;
|
||||
this.numContacts = 0;
|
||||
|
||||
for (var body1_index = 0; body1_index < bl; body1_index++)
|
||||
for (var body1Index = 0; body1Index < this._bl; body1Index++)
|
||||
{
|
||||
var body1: Body = this.bodyArr[body1_index];
|
||||
|
||||
if (!body1)
|
||||
if (!this.bodies[body1Index])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
body1.stepCount = this.stepCount;
|
||||
this.bodies[body1Index].stepCount = this.stepCount;
|
||||
|
||||
for (var body2_index = 0; body2_index < bl; body2_index++)
|
||||
for (var body2Index = 0; body2Index < this._bl; body2Index++)
|
||||
{
|
||||
var body2: Body = this.bodyArr[body2_index];
|
||||
|
||||
if (body1.inContact(body2) == false)
|
||||
if (this.bodies[body1Index].inContact(this.bodies[body2Index]) == false)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Manager.write('body1 and body2 intersect');
|
||||
|
||||
for (var i = 0; i < body1.shapes.length; i++)
|
||||
for (var i = 0; i < this.bodies[body1Index].shapesLength; i++)
|
||||
{
|
||||
for (var j = 0; j < body2.shapes.length; j++)
|
||||
for (var j = 0; j < this.bodies[body2Index].shapesLength; j++)
|
||||
{
|
||||
var shape1 = body1.shapes[i];
|
||||
var shape2 = body2.shapes[j];
|
||||
this._shape1 = this.bodies[body1Index].shapes[i];
|
||||
this._shape2 = this.bodies[body2Index].shapes[j];
|
||||
|
||||
var contactArr = [];
|
||||
|
||||
if (!Manager.collision.collide(shape1, shape2, contactArr))
|
||||
if (!Manager.collision.collide(this._shape1, this._shape2, contactArr))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (shape1.type > shape2.type)
|
||||
if (this._shape1.type > this._shape2.type)
|
||||
{
|
||||
var temp = shape1;
|
||||
shape1 = shape2;
|
||||
shape2 = temp;
|
||||
var temp = this._shape1;
|
||||
this._shape1 = this._shape2;
|
||||
this._shape2 = temp;
|
||||
}
|
||||
|
||||
this.numContacts += contactArr.length;
|
||||
|
||||
var contactSolver = this.findContactSolver(shape1, shape2);
|
||||
// Result stored in this._contactSolver (see what we can do about generating some re-usable solvers)
|
||||
var contactSolver: ContactSolver = this.findContactSolver(this._shape1, this._shape2);
|
||||
|
||||
Manager.write('findContactSolver result: ' + contactSolver);
|
||||
|
||||
if (contactSolver)
|
||||
{
|
||||
contactSolver.update(contactArr);
|
||||
newContactSolverArr.push(contactSolver);
|
||||
this.contactSolvers.push(contactSolver);
|
||||
}
|
||||
else
|
||||
{
|
||||
Manager.write('awake both bodies');
|
||||
|
||||
body1.awake(true);
|
||||
body2.awake(true);
|
||||
this.bodies[body1Index].awake(true);
|
||||
this.bodies[body2Index].awake(true);
|
||||
|
||||
var newContactSolver = new ContactSolver(shape1, shape2);
|
||||
var newContactSolver = new ContactSolver(this._shape1, this._shape2);
|
||||
newContactSolver.contacts = contactArr;
|
||||
newContactSolver.elasticity = Math.max(shape1.elasticity, shape2.elasticity);
|
||||
newContactSolver.friction = Math.sqrt(shape1.friction * shape2.friction);
|
||||
newContactSolverArr.push(newContactSolver);
|
||||
newContactSolver.elasticity = Math.max(this._shape1.elasticity, this._shape2.elasticity);
|
||||
newContactSolver.friction = Math.sqrt(this._shape1.friction * this._shape2.friction);
|
||||
|
||||
this.contactSolvers.push(newContactSolver);
|
||||
Manager.write('new contact solver');
|
||||
//console.log(newContactSolver);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return newContactSolverArr;
|
||||
this._cl = this.contactSolvers.length;
|
||||
|
||||
}
|
||||
|
||||
public initSolver(dt, dt_inv, warmStarting) {
|
||||
private initSolver(warmStarting) {
|
||||
|
||||
Manager.write('initSolver');
|
||||
Manager.write('contactSolvers.length: ' + this.contactSolvers.length);
|
||||
|
||||
//var t0 = Date.now();
|
||||
Manager.write('contactSolvers.length: ' + this._cl);
|
||||
|
||||
// Initialize contact solvers
|
||||
for (var i = 0; i < this.contactSolvers.length; i++)
|
||||
for (var c = 0; c < this._cl; c++)
|
||||
{
|
||||
this.contactSolvers[i].initSolver(dt_inv);
|
||||
this.contactSolvers[c].initSolver(this._deltaInv);
|
||||
|
||||
// Warm starting (apply cached impulse)
|
||||
if (warmStarting)
|
||||
{
|
||||
this.contactSolvers[c].warmStart();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Initialize joint solver
|
||||
for (var i = 0; i < this.jointArr.length; i++)
|
||||
for (var j = 0; j < this.joints.length; j++)
|
||||
{
|
||||
if (this.jointArr[i])
|
||||
if (this.joints[j])
|
||||
{
|
||||
this.jointArr[i].initSolver(dt, warmStarting);
|
||||
this.joints[j].initSolver(this._delta, warmStarting);
|
||||
}
|
||||
}
|
||||
|
||||
// Warm starting (apply cached impulse)
|
||||
/*
|
||||
if (warmStarting)
|
||||
{
|
||||
for (var i = 0; i < this.contactSolvers.length; i++)
|
||||
for (var c = 0; c < this._cl; c++)
|
||||
{
|
||||
this.contactSolvers[i].warmStart();
|
||||
this.contactSolvers[c].warmStart();
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
//stats.timeInitSolver = Date.now() - t0;
|
||||
}
|
||||
|
||||
public velocitySolver(iteration) {
|
||||
private velocitySolver(iterations:number) {
|
||||
|
||||
Manager.write('velocitySolver, iterations: ' + iteration + ' csa len: ' + this.contactSolvers.length);
|
||||
Manager.write('velocitySolver, iterations: ' + iterations + ' csa len: ' + this._cl);
|
||||
|
||||
//var t0 = Date.now();
|
||||
|
||||
for (var i = 0; i < iteration; i++)
|
||||
for (var i = 0; i < iterations; i++)
|
||||
{
|
||||
for (var j = 0; j < this.jointArr.length; j++)
|
||||
for (var j = 0; j < this._jl; j++)
|
||||
{
|
||||
if (this.jointArr[j])
|
||||
if (this.joints[j])
|
||||
{
|
||||
this.jointArr[j].solveVelocityConstraints();
|
||||
this.joints[j].solveVelocityConstraints();
|
||||
}
|
||||
}
|
||||
|
||||
for (var j = 0; j < this.contactSolvers.length; j++)
|
||||
for (var c = 0; c < this._cl; c++)
|
||||
{
|
||||
this.contactSolvers[j].solveVelocityConstraints();
|
||||
this.contactSolvers[c].solveVelocityConstraints();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public positionSolver(iteration) {
|
||||
private positionSolver(iterations:number):bool {
|
||||
|
||||
var positionSolved = false;
|
||||
this._positionSolved = false;
|
||||
|
||||
for (var i = 0; i < iteration; i++)
|
||||
for (var i = 0; i < iterations; i++)
|
||||
{
|
||||
var contactsOk = true;
|
||||
var jointsOk = true;
|
||||
this._contactsOk = true;
|
||||
this._jointsOk = true;
|
||||
|
||||
for (var j = 0; j < this.contactSolvers.length; j++)
|
||||
for (var c = 0; c < this._cl; c++)
|
||||
{
|
||||
var contactOk = this.contactSolvers[j].solvePositionConstraints();
|
||||
contactsOk = contactOk && contactsOk;
|
||||
this._contactsOk = this.contactSolvers[c].solvePositionConstraints() && this._contactsOk;
|
||||
}
|
||||
|
||||
for (var j = 0; j < this.jointArr.length; j++)
|
||||
for (var j = 0; j < this._jl; j++)
|
||||
{
|
||||
if (this.jointArr[j])
|
||||
if (this.joints[j])
|
||||
{
|
||||
var jointOk = this.jointArr[j].solvePositionConstraints();
|
||||
jointsOk = jointOk && jointsOk;
|
||||
this._jointsOk = this.joints[j].solvePositionConstraints() && this._jointsOk;
|
||||
}
|
||||
}
|
||||
|
||||
if (contactsOk && jointsOk)
|
||||
if (this._contactsOk && this._jointsOk)
|
||||
{
|
||||
// exit early if the position errors are small
|
||||
positionSolved = true;
|
||||
this._positionSolved = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return positionSolved;
|
||||
return this._positionSolved;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public step(dt, vel_iteration, pos_iteration, warmStarting, allowSleep) {
|
||||
// Step through the physics simulation
|
||||
public step(dt: number, velocityIterations: number, positionIterations: number, warmStarting: bool, allowSleep: bool) {
|
||||
|
||||
Manager.clear();
|
||||
Manager.write('Space step ' + this.stepCount);
|
||||
|
||||
var dt_inv: number = 1 / dt;
|
||||
var bl: number = this.bodyArr.length;
|
||||
var jl: number = this.jointArr.length;
|
||||
this._delta = dt;
|
||||
this._deltaInv = 1 / dt;
|
||||
this._bl = this.bodies.length;
|
||||
this._jl = this.joints.length;
|
||||
|
||||
this.stepCount++;
|
||||
|
||||
// 1) Generate Contact Solvers
|
||||
this.contactSolvers = this.genTemporalContactSolvers();
|
||||
// 1) Generate Contact Solvers (into the this.contactSolvers array)
|
||||
this.genTemporalContactSolvers();
|
||||
|
||||
Manager.dump("Contact Solvers", this.bodyArr[1]);
|
||||
Manager.dump("Contact Solvers", this.bodies[1]);
|
||||
|
||||
// 2) Initialize the Contact Solvers
|
||||
this.initSolver(dt, dt_inv, warmStarting);
|
||||
this.initSolver(warmStarting);
|
||||
|
||||
Manager.dump("Init Solver", this.bodyArr[1]);
|
||||
Manager.dump("Init Solver", this.bodies[1]);
|
||||
|
||||
// 3) Intergrate velocity
|
||||
for (var i = 0; i < bl; i++)
|
||||
for (var i = 0; i < this._bl; i++)
|
||||
{
|
||||
if (this.bodyArr[i] && this.bodyArr[i].isDynamic && this.bodyArr[i].isAwake)
|
||||
if (this.bodies[i] && this.bodies[i].isDynamic && this.bodies[i].isAwake)
|
||||
{
|
||||
this.bodyArr[i].updateVelocity(this.gravity, dt, this.damping);
|
||||
this.bodies[i].updateVelocity(this.gravity, this._delta, this.damping);
|
||||
}
|
||||
}
|
||||
|
||||
Manager.dump("Update Velocity", this.bodyArr[1]);
|
||||
Manager.dump("Update Velocity", this.bodies[1]);
|
||||
|
||||
/*
|
||||
// 4) Awaken bodies
|
||||
for (var j = 0; i < jl; j++)
|
||||
// 4) Awaken bodies via joints
|
||||
for (var j = 0; i < this._jl; j++)
|
||||
{
|
||||
var joint = this.jointArr[j];
|
||||
|
||||
if (!joint)
|
||||
if (!this.joints[j])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var body1 = joint.body1;
|
||||
var body2 = joint.body2;
|
||||
|
||||
var awake1 = body1.isAwake && !body1.isStatic;
|
||||
var awake2 = body2.isAwake && !body2.isStatic;
|
||||
// combine
|
||||
var awake1 = this.joints[j].body1.isAwake && !this.joints[j].body1.isStatic;
|
||||
var awake2 = this.joints[j].body2.isAwake && !this.joints[j].body2.isStatic;
|
||||
|
||||
if (awake1 ^ awake2)
|
||||
{
|
||||
if (!awake1)
|
||||
{
|
||||
body1.awake(true);
|
||||
this.joints[j].body1.awake(true);
|
||||
}
|
||||
|
||||
|
||||
if (!awake2)
|
||||
{
|
||||
body2.awake(true);
|
||||
this.joints[j].body2.awake(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// 5) Iterative velocity constraints solver
|
||||
this.velocitySolver(vel_iteration);
|
||||
this.velocitySolver(velocityIterations);
|
||||
|
||||
Manager.dump("Velocity Solvers", this.bodyArr[1]);
|
||||
Manager.dump("Velocity Solvers", this.bodies[1]);
|
||||
|
||||
// 6) Intergrate position
|
||||
for (var i = 0; i < bl; i++)
|
||||
// 6) Integrate position
|
||||
for (var i = 0; i < this._bl; i++)
|
||||
{
|
||||
if (this.bodyArr[i] && this.bodyArr[i].isDynamic && this.bodyArr[i].isAwake)
|
||||
if (this.bodies[i] && this.bodies[i].isDynamic && this.bodies[i].isAwake)
|
||||
{
|
||||
this.bodyArr[i].updatePosition(dt);
|
||||
this.bodies[i].updatePosition(this._delta);
|
||||
}
|
||||
}
|
||||
|
||||
Manager.dump("Update Position", this.bodyArr[1]);
|
||||
Manager.dump("Update Position", this.bodies[1]);
|
||||
|
||||
// 7) Process breakable joint
|
||||
for (var i = 0; i < jl; i++)
|
||||
for (var i = 0; i < this._jl; i++)
|
||||
{
|
||||
if (this.jointArr[i] && this.jointArr[i].breakable && (this.jointArr[i].getReactionForce(dt_inv).lengthSq() >= this.jointArr[i].maxForce * this.jointArr[i].maxForce))
|
||||
if (this.joints[i] && this.joints[i].breakable && (this.joints[i].getReactionForce(this._deltaInv).lengthSq() >= this.joints[i].maxForce * this.joints[i].maxForce))
|
||||
{
|
||||
this.removeJoint(this.jointArr[i]);
|
||||
this.removeJoint(this.joints[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// 8) Iterative position constraints solver
|
||||
var positionSolved = this.positionSolver(pos_iteration);
|
||||
// 8) Iterative position constraints solver (result stored in this._positionSolved)
|
||||
this.positionSolver(positionIterations);
|
||||
|
||||
Manager.dump("Position Solver", this.bodyArr[1]);
|
||||
Manager.dump("Position Solver", this.bodies[1]);
|
||||
|
||||
// 9) Sync the Transforms
|
||||
for (var i = 0; i < bl; i++)
|
||||
for (var i = 0; i < this._bl; i++)
|
||||
{
|
||||
if (this.bodyArr[i])
|
||||
if (this.bodies[i])
|
||||
{
|
||||
this.bodyArr[i].syncTransform();
|
||||
this.bodies[i].syncTransform();
|
||||
}
|
||||
}
|
||||
|
||||
Manager.dump("Sync Transform", this.bodyArr[1]);
|
||||
Manager.dump("Sync Transform", this.bodies[1]);
|
||||
|
||||
// 10) Post solve collision callback
|
||||
for (var i = 0; i < this.contactSolvers.length; i++)
|
||||
if (this.postSolve)
|
||||
{
|
||||
var arb = this.contactSolvers[i];
|
||||
// Re-enable this
|
||||
//this.postSolve(arb);
|
||||
for (var i = 0; i < this._cl; i++)
|
||||
{
|
||||
this.postSolve(this.contactSolvers[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// 11) Cache Body Data
|
||||
for (var i = 0; i < bl; i++)
|
||||
for (var i = 0; i < this._bl; i++)
|
||||
{
|
||||
if (this.bodyArr[i] && this.bodyArr[i].isDynamic && this.bodyArr[i].isAwake)
|
||||
if (this.bodies[i] && this.bodies[i].isDynamic && this.bodies[i].isAwake)
|
||||
{
|
||||
this.bodyArr[i].cacheData('post solve collision callback');
|
||||
this.bodies[i].cacheData('post solve collision callback');
|
||||
}
|
||||
}
|
||||
|
||||
Manager.dump("Cache Data", this.bodyArr[1]);
|
||||
Manager.dump("Cache Data", this.bodies[1]);
|
||||
|
||||
Manager.writeAll();
|
||||
|
||||
// 12) Process sleeping
|
||||
/*
|
||||
if (allowSleep)
|
||||
{
|
||||
var minSleepTime = 999999;
|
||||
this._minSleepTime = 999999;
|
||||
|
||||
var linTolSqr = Space.SLEEP_LINEAR_TOLERANCE * Space.SLEEP_LINEAR_TOLERANCE;
|
||||
var angTolSqr = Space.SLEEP_ANGULAR_TOLERANCE * Space.SLEEP_ANGULAR_TOLERANCE;
|
||||
|
||||
for (var i = 0; i < bl; i++)
|
||||
for (var i = 0; i < this._bl; i++)
|
||||
{
|
||||
var body = this.bodyArr[i];
|
||||
|
||||
if (!this.bodyArr[i] || this.bodyArr[i].isDynamic == false)
|
||||
if (!this.bodies[i] || this.bodies[i].isDynamic == false)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (body.angularVelocity * body.angularVelocity > angTolSqr || body.velocity.dot(body.velocity) > linTolSqr)
|
||||
if (this.bodies[i].angularVelocity * this.bodies[i].angularVelocity > this._angTolSqr || this.bodies[i].velocity.dot(this.bodies[i].velocity) > this._linTolSqr)
|
||||
{
|
||||
body.sleepTime = 0;
|
||||
minSleepTime = 0;
|
||||
this.bodies[i].sleepTime = 0;
|
||||
this._minSleepTime = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
body.sleepTime += dt;
|
||||
minSleepTime = Math.min(minSleepTime, body.sleepTime);
|
||||
this.bodies[i].sleepTime += this._delta;
|
||||
this._minSleepTime = Math.min(this._minSleepTime, this.bodies[i].sleepTime);
|
||||
}
|
||||
}
|
||||
|
||||
if (positionSolved && minSleepTime >= Space.TIME_TO_SLEEP)
|
||||
if (this._positionSolved && this._minSleepTime >= Space.TIME_TO_SLEEP)
|
||||
{
|
||||
for (var i = 0; i < this.bodyArr.length; i++)
|
||||
for (var i = 0; i < this._bl; i++)
|
||||
{
|
||||
var body = this.bodyArr[i];
|
||||
|
||||
if (!body)
|
||||
if (this.bodies[i])
|
||||
{
|
||||
continue;
|
||||
this.bodies[i].awake(false);
|
||||
}
|
||||
|
||||
body.awake(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
}
|
|
@ -1,692 +0,0 @@
|
|||
/// <reference path="../../math/Vec2.ts" />
|
||||
/// <reference path="../../geom/Point.ts" />
|
||||
/// <reference path="../../math/Vec2Utils.ts" />
|
||||
/// <reference path="../../math/Transform.ts" />
|
||||
/// <reference path="../../math/TransformUtils.ts" />
|
||||
/// <reference path="Manager.ts" />
|
||||
/// <reference path="joints/Joint.ts" />
|
||||
/// <reference path="Bounds.ts" />
|
||||
/// <reference path="Space.ts" />
|
||||
/// <reference path="shapes/IShape.ts" />
|
||||
/// <reference path="shapes/Triangle.ts" />
|
||||
/// <reference path="shapes/Circle.ts" />
|
||||
/// <reference path="shapes/Box.ts" />
|
||||
/// <reference path="shapes/Poly.ts" />
|
||||
/// <reference path="shapes/Segment.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - Advanced Physics - Body
|
||||
*
|
||||
* Based on the work Ju Hyung Lee started in JS PhyRus.
|
||||
*/
|
||||
|
||||
module Phaser.Physics.Advanced {
|
||||
|
||||
export class Body {
|
||||
|
||||
constructor(sprite: Phaser.Sprite, type: number, x?: number = 0, y?: number = 0) {
|
||||
|
||||
this.id = Phaser.Physics.Advanced.Manager.bodyCounter++;
|
||||
this.name = 'body' + this.id;
|
||||
this.type = type;
|
||||
|
||||
if (sprite)
|
||||
{
|
||||
this.sprite = sprite;
|
||||
this.game = sprite.game;
|
||||
this.position = new Phaser.Vec2(Phaser.Physics.Advanced.Manager.pixelsToMeters(sprite.x), Phaser.Physics.Advanced.Manager.pixelsToMeters(sprite.y));
|
||||
this.angle = sprite.rotation;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.position = new Phaser.Vec2(Phaser.Physics.Advanced.Manager.pixelsToMeters(x), Phaser.Physics.Advanced.Manager.pixelsToMeters(y));
|
||||
this.angle = 0;
|
||||
}
|
||||
|
||||
this.transform = new Phaser.Transform(this.position, this.angle);
|
||||
this.centroid = new Phaser.Vec2;
|
||||
this.velocity = new Phaser.Vec2;
|
||||
this.force = new Phaser.Vec2;
|
||||
this.angularVelocity = 0;
|
||||
this.torque = 0;
|
||||
this.linearDamping = 0;
|
||||
this.angularDamping = 0;
|
||||
this.sleepTime = 0;
|
||||
this.awaked = false;
|
||||
|
||||
this.shapes = [];
|
||||
this.joints = [];
|
||||
this.jointHash = {};
|
||||
|
||||
this.bounds = new Bounds;
|
||||
|
||||
this.fixedRotation = false;
|
||||
|
||||
this.categoryBits = 0x0001;
|
||||
this.maskBits = 0xFFFF;
|
||||
|
||||
this.stepCount = 0;
|
||||
|
||||
}
|
||||
|
||||
public toString(): string {
|
||||
return "[{Body (name=" + this.name + " velocity=" + this.velocity.toString() + " angularVelocity: " + this.angularVelocity + ")}]";
|
||||
}
|
||||
|
||||
private _tempVec2: Phaser.Vec2 = new Phaser.Vec2;
|
||||
|
||||
/**
|
||||
* Reference to Phaser.Game
|
||||
*/
|
||||
public game: Game;
|
||||
|
||||
/**
|
||||
* Reference to the parent Sprite
|
||||
*/
|
||||
public sprite: Phaser.Sprite;
|
||||
|
||||
/**
|
||||
* The Body ID
|
||||
*/
|
||||
public id: number;
|
||||
|
||||
/**
|
||||
* The Body name
|
||||
*/
|
||||
public name: string;
|
||||
|
||||
/**
|
||||
* 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 angle: number;
|
||||
|
||||
// Local to world transform
|
||||
public transform: Phaser.Transform;
|
||||
|
||||
// Local center of mass
|
||||
public centroid: Phaser.Vec2;
|
||||
|
||||
// World position of centroid
|
||||
public position: Phaser.Vec2;
|
||||
|
||||
// Velocity
|
||||
public velocity: Phaser.Vec2;
|
||||
|
||||
// Force
|
||||
public force: Phaser.Vec2;
|
||||
|
||||
// Angular velocity
|
||||
public angularVelocity: number;
|
||||
|
||||
// Torque
|
||||
public torque: number;
|
||||
|
||||
// Linear damping
|
||||
public linearDamping: number;
|
||||
|
||||
// Angular damping
|
||||
public angularDamping: number;
|
||||
|
||||
// Sleep time
|
||||
public sleepTime: number;
|
||||
|
||||
// Awaked
|
||||
public awaked: bool;
|
||||
|
||||
// Shapes
|
||||
public shapes: IShape[] = [];
|
||||
|
||||
// Joints
|
||||
public joints: IJoint[] = [];
|
||||
public jointHash = {};
|
||||
|
||||
// Bounds of all shapes
|
||||
public bounds: Bounds;
|
||||
|
||||
public mass: number;
|
||||
public massInverted: number;
|
||||
public inertia: number;
|
||||
public inertiaInverted: number;
|
||||
|
||||
public fixedRotation = false;
|
||||
public categoryBits = 0x0001;
|
||||
public maskBits = 0xFFFF;
|
||||
public stepCount = 0;
|
||||
public space: Space;
|
||||
|
||||
public duplicate() {
|
||||
|
||||
//console.log('body duplicate called');
|
||||
|
||||
//var body = new Body(this.type, this.transform.t, this.angle);
|
||||
|
||||
//for (var i = 0; i < this.shapes.length; i++)
|
||||
//{
|
||||
// body.addShape(this.shapes[i].duplicate());
|
||||
//}
|
||||
|
||||
//body.resetMassData();
|
||||
|
||||
//return body;
|
||||
|
||||
}
|
||||
|
||||
public get isDisabled(): bool {
|
||||
return this.type == Phaser.Types.BODY_DISABLED ? true : false;
|
||||
}
|
||||
|
||||
public get isStatic(): bool {
|
||||
return this.type == Phaser.Types.BODY_STATIC ? true : false;
|
||||
}
|
||||
|
||||
public get isKinetic(): bool {
|
||||
return this.type == Phaser.Types.BODY_KINETIC ? true : false;
|
||||
}
|
||||
|
||||
public get isDynamic(): bool {
|
||||
return this.type == Phaser.Types.BODY_DYNAMIC ? true : false;
|
||||
}
|
||||
|
||||
public setType(type: number) {
|
||||
|
||||
if (type == this.type)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.force.setTo(0, 0);
|
||||
this.velocity.setTo(0, 0);
|
||||
this.torque = 0;
|
||||
this.angularVelocity = 0;
|
||||
this.type = type;
|
||||
|
||||
this.awake(true);
|
||||
|
||||
}
|
||||
|
||||
public addPoly(verts, elasticity?: number = 1, friction?: number = 1, density?: number = 1): Phaser.Physics.Advanced.Shapes.Poly {
|
||||
|
||||
var poly: Phaser.Physics.Advanced.Shapes.Poly = new Phaser.Physics.Advanced.Shapes.Poly(verts);
|
||||
poly.elasticity = elasticity;
|
||||
poly.friction = friction;
|
||||
poly.density = density;
|
||||
|
||||
this.addShape(poly);
|
||||
this.resetMassData();
|
||||
|
||||
return poly;
|
||||
|
||||
}
|
||||
|
||||
public addTriangle(x1: number, y1: number, x2: number, y2: number, x3: number, y3: number, elasticity?: number = 1, friction?: number = 1, density?: number = 1): Phaser.Physics.Advanced.Shapes.Triangle {
|
||||
|
||||
var tri: Phaser.Physics.Advanced.Shapes.Triangle = new Phaser.Physics.Advanced.Shapes.Triangle(x1, y1, x2, y2, x3, y3);
|
||||
tri.elasticity = elasticity;
|
||||
tri.friction = friction;
|
||||
tri.density = density;
|
||||
|
||||
this.addShape(tri);
|
||||
this.resetMassData();
|
||||
|
||||
return tri;
|
||||
|
||||
}
|
||||
|
||||
public addBox(x: number, y: number, width: number, height: number, elasticity?: number = 1, friction?: number = 1, density?: number = 1): Phaser.Physics.Advanced.Shapes.Box {
|
||||
|
||||
var box: Phaser.Physics.Advanced.Shapes.Box = new Phaser.Physics.Advanced.Shapes.Box(x, y, width, height);
|
||||
box.elasticity = elasticity;
|
||||
box.friction = friction;
|
||||
box.density = density;
|
||||
|
||||
this.addShape(box);
|
||||
this.resetMassData();
|
||||
|
||||
return box;
|
||||
|
||||
}
|
||||
|
||||
public addCircle(radius: number, x?: number = 0, y?: number = 0, elasticity?: number = 1, friction?: number = 1, density?: number = 1): Phaser.Physics.Advanced.Shapes.Circle {
|
||||
|
||||
var circle: Phaser.Physics.Advanced.Shapes.Circle = new Phaser.Physics.Advanced.Shapes.Circle(radius, x, y);
|
||||
circle.elasticity = elasticity;
|
||||
circle.friction = friction;
|
||||
circle.density = density;
|
||||
|
||||
this.addShape(circle);
|
||||
this.resetMassData();
|
||||
|
||||
return circle;
|
||||
|
||||
}
|
||||
|
||||
public addShape(shape) {
|
||||
|
||||
// Check not already part of this body
|
||||
shape.body = this;
|
||||
|
||||
this.shapes.push(shape);
|
||||
|
||||
return shape;
|
||||
|
||||
}
|
||||
|
||||
public removeShape(shape) {
|
||||
|
||||
var index = this.shapes.indexOf(shape);
|
||||
|
||||
if (index != -1)
|
||||
{
|
||||
this.shapes.splice(index, 1);
|
||||
shape.body = undefined;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private setMass(mass) {
|
||||
|
||||
this.mass = mass;
|
||||
this.massInverted = mass > 0 ? 1 / mass : 0;
|
||||
|
||||
}
|
||||
|
||||
private setInertia(inertia) {
|
||||
|
||||
this.inertia = inertia;
|
||||
this.inertiaInverted = inertia > 0 ? 1 / inertia : 0;
|
||||
|
||||
}
|
||||
|
||||
public setTransform(pos, angle) {
|
||||
|
||||
this.transform.setTo(pos, angle);
|
||||
// inject the transform into this.position
|
||||
Manager.write('setTransform: ' + this.position.toString());
|
||||
Manager.write('centroid: ' + this.centroid.toString());
|
||||
Phaser.TransformUtils.transform(this.transform, this.centroid, this.position);
|
||||
Manager.write('post setTransform: ' + this.position.toString());
|
||||
//this.position.copyFrom(this.transform.transform(this.centroid));
|
||||
this.angle = angle;
|
||||
|
||||
}
|
||||
|
||||
public syncTransform() {
|
||||
|
||||
Manager.write('syncTransform:');
|
||||
Manager.write('p: ' + this.position.toString());
|
||||
Manager.write('centroid: ' + this.centroid.toString());
|
||||
Manager.write('xf: ' + this.transform.toString());
|
||||
Manager.write('a: ' + this.angle);
|
||||
this.transform.setRotation(this.angle);
|
||||
// OPTIMISE: Creating new vector
|
||||
Phaser.Vec2Utils.subtract(this.position, Phaser.TransformUtils.rotate(this.transform, this.centroid), this.transform.t);
|
||||
Manager.write('--------------------');
|
||||
Manager.write('xf: ' + this.transform.toString());
|
||||
Manager.write('--------------------');
|
||||
|
||||
}
|
||||
|
||||
public getWorldPoint(p:Phaser.Vec2) {
|
||||
// OPTIMISE: Creating new vector
|
||||
return Phaser.TransformUtils.transform(this.transform, p);
|
||||
}
|
||||
|
||||
public getWorldVector(v:Phaser.Vec2) {
|
||||
// OPTIMISE: Creating new vector
|
||||
return Phaser.TransformUtils.rotate(this.transform, v);
|
||||
}
|
||||
|
||||
public getLocalPoint(p:Phaser.Vec2) {
|
||||
// OPTIMISE: Creating new vector
|
||||
return Phaser.TransformUtils.untransform(this.transform, p);
|
||||
}
|
||||
|
||||
public getLocalVector(v:Phaser.Vec2) {
|
||||
// OPTIMISE: Creating new vector
|
||||
return Phaser.TransformUtils.unrotate(this.transform, v);
|
||||
}
|
||||
|
||||
public setFixedRotation(flag) {
|
||||
this.fixedRotation = flag;
|
||||
this.resetMassData();
|
||||
}
|
||||
|
||||
public resetMassData() {
|
||||
|
||||
this.centroid.setTo(0, 0);
|
||||
this.mass = 0;
|
||||
this.massInverted = 0;
|
||||
this.inertia = 0;
|
||||
this.inertiaInverted = 0;
|
||||
|
||||
if (this.isDynamic == false)
|
||||
{
|
||||
Phaser.TransformUtils.transform(this.transform, this.centroid, this.position);
|
||||
//this.position.copyFrom(this.transform.transform(this.centroid));
|
||||
return;
|
||||
}
|
||||
|
||||
var totalMassCentroid = new Phaser.Vec2(0, 0);
|
||||
var totalMass = 0;
|
||||
var totalInertia = 0;
|
||||
|
||||
for (var i = 0; i < this.shapes.length; i++)
|
||||
{
|
||||
var shape = this.shapes[i];
|
||||
var centroid = shape.centroid();
|
||||
var mass = shape.area() * shape.density;
|
||||
var inertia = shape.inertia(mass);
|
||||
|
||||
//console.log('rmd', centroid, shape);
|
||||
|
||||
totalMassCentroid.multiplyAddByScalar(centroid, mass);
|
||||
totalMass += mass;
|
||||
totalInertia += inertia;
|
||||
}
|
||||
|
||||
//this.centroid.copy(vec2.scale(totalMassCentroid, 1 / totalMass));
|
||||
Phaser.Vec2Utils.scale(totalMassCentroid, 1 / totalMass, this.centroid);
|
||||
|
||||
this.setMass(totalMass);
|
||||
|
||||
if (!this.fixedRotation)
|
||||
{
|
||||
//this.setInertia(totalInertia - totalMass * vec2.dot(this.centroid, this.centroid));
|
||||
this.setInertia(totalInertia - totalMass * Phaser.Vec2Utils.dot(this.centroid, this.centroid));
|
||||
}
|
||||
|
||||
//console.log("mass = " + this.m + " inertia = " + this.i);
|
||||
|
||||
// Move center of mass
|
||||
var oldPosition: Phaser.Vec2 = Phaser.Vec2Utils.clone(this.position);
|
||||
//this.position.copyFrom(this.transform.transform(this.centroid));
|
||||
Phaser.TransformUtils.transform(this.transform, this.centroid, this.position);
|
||||
|
||||
// Update center of mass velocity
|
||||
|
||||
//this.velocity.mad(vec2.perp(vec2.sub(this.position, old_p)), this.angularVelocity);
|
||||
oldPosition.subtract(this.position);
|
||||
this.velocity.multiplyAddByScalar(Phaser.Vec2Utils.perp(oldPosition, oldPosition), this.angularVelocity);
|
||||
|
||||
}
|
||||
|
||||
public resetJointAnchors() {
|
||||
|
||||
for (var i = 0; i < this.joints.length; i++)
|
||||
{
|
||||
var joint = this.joints[i];
|
||||
|
||||
if (!joint)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var anchor1 = joint.getWorldAnchor1();
|
||||
var anchor2 = joint.getWorldAnchor2();
|
||||
|
||||
joint.setWorldAnchor1(anchor1);
|
||||
joint.setWorldAnchor2(anchor2);
|
||||
}
|
||||
}
|
||||
|
||||
public cacheData(source:string = '') {
|
||||
|
||||
Manager.write('cacheData -- start');
|
||||
Manager.write('p: ' + this.position.toString());
|
||||
Manager.write('xf: ' + this.transform.toString());
|
||||
|
||||
this.bounds.clear();
|
||||
|
||||
for (var i = 0; i < this.shapes.length; i++)
|
||||
{
|
||||
var shape: IShape = this.shapes[i];
|
||||
shape.cacheData(this.transform);
|
||||
this.bounds.addBounds(shape.bounds);
|
||||
}
|
||||
|
||||
Manager.write('bounds: ' + this.bounds.toString());
|
||||
|
||||
Manager.write('p: ' + this.position.toString());
|
||||
Manager.write('xf: ' + this.transform.toString());
|
||||
Manager.write('cacheData -- stop');
|
||||
|
||||
}
|
||||
|
||||
public updateVelocity(gravity, dt, damping) {
|
||||
|
||||
// this.velocity = vec2.mad(this.velocity, vec2.mad(gravity, this.force, this.massInverted), dt);
|
||||
Phaser.Vec2Utils.multiplyAdd(gravity, this.force, this.massInverted, this._tempVec2);
|
||||
Phaser.Vec2Utils.multiplyAdd(this.velocity, this._tempVec2, dt, this.velocity);
|
||||
|
||||
this.angularVelocity = this.angularVelocity + this.torque * this.inertiaInverted * dt;
|
||||
|
||||
// Apply damping.
|
||||
// ODE: dv/dt + c * v = 0
|
||||
// Solution: v(t) = v0 * exp(-c * t)
|
||||
// Time step: v(t + dt) = v0 * exp(-c * (t + dt)) = v0 * exp(-c * t) * exp(-c * dt) = v * exp(-c * dt)
|
||||
// v2 = exp(-c * dt) * v1
|
||||
// Taylor expansion:
|
||||
// v2 = (1.0f - c * dt) * v1
|
||||
this.velocity.scale(this.clamp(1 - dt * (damping + this.linearDamping), 0, 1));
|
||||
this.angularVelocity *= this.clamp(1 - dt * (damping + this.angularDamping), 0, 1);
|
||||
|
||||
this.force.setTo(0, 0);
|
||||
this.torque = 0;
|
||||
|
||||
}
|
||||
|
||||
public inContact(body2: Body): bool {
|
||||
|
||||
if (!body2 || this.stepCount == body2.stepCount)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(this.isAwake && this.isStatic == false) && !(body2.isAwake && body2.isStatic == false))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.isCollidable(body2) == false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!this.bounds.intersectsBounds(body2.bounds))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public clamp(v, min, max) {
|
||||
return v < min ? min : (v > max ? max : v);
|
||||
}
|
||||
|
||||
public updatePosition(dt) {
|
||||
|
||||
//console.log('body update pos', this.position.y);
|
||||
//console.log('pre add temp', this._tempVec2.y);
|
||||
|
||||
//this.position.addself(vec2.scale(this.velocity, dt));
|
||||
this.position.add(Phaser.Vec2Utils.scale(this.velocity, dt, this._tempVec2));
|
||||
|
||||
//console.log('post add temp', this._tempVec2.y);
|
||||
//console.log('post add', this.position.y);
|
||||
|
||||
this.angle += this.angularVelocity * dt;
|
||||
|
||||
}
|
||||
|
||||
public resetForce() {
|
||||
this.force.setTo(0, 0);
|
||||
this.torque = 0;
|
||||
}
|
||||
|
||||
public applyForce(force:Phaser.Vec2, p:Phaser.Vec2) {
|
||||
|
||||
if (this.isDynamic == false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.isAwake == false)
|
||||
{
|
||||
this.awake(true);
|
||||
}
|
||||
|
||||
this.force.add(force);
|
||||
|
||||
// this.f.addself(force);
|
||||
// this.torque += vec2.cross(vec2.sub(p, this.p), force);
|
||||
|
||||
Phaser.Vec2Utils.subtract(p, this.position, this._tempVec2);
|
||||
this.torque += Phaser.Vec2Utils.cross(this._tempVec2, force);
|
||||
|
||||
}
|
||||
|
||||
public applyForceToCenter(force:Phaser.Vec2) {
|
||||
|
||||
if (this.isDynamic == false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.isAwake == false)
|
||||
{
|
||||
this.awake(true);
|
||||
}
|
||||
|
||||
this.force.add(force);
|
||||
|
||||
}
|
||||
|
||||
public applyTorque(torque:number) {
|
||||
|
||||
if (this.isDynamic == false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.isAwake == false)
|
||||
{
|
||||
this.awake(true);
|
||||
}
|
||||
|
||||
this.torque += torque;
|
||||
|
||||
}
|
||||
|
||||
public applyLinearImpulse(impulse:Phaser.Vec2, p:Phaser.Vec2) {
|
||||
|
||||
if (this.isDynamic == false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.isAwake == false)
|
||||
{
|
||||
this.awake(true);
|
||||
}
|
||||
|
||||
this.velocity.multiplyAddByScalar(impulse, this.massInverted);
|
||||
|
||||
// this.angularVelocity += vec2.cross(vec2.sub(p, this.position), impulse) * this.inertiaInverted;
|
||||
|
||||
Phaser.Vec2Utils.subtract(p, this.position, this._tempVec2);
|
||||
|
||||
this.angularVelocity += Phaser.Vec2Utils.cross(this._tempVec2, impulse) * this.inertiaInverted;
|
||||
|
||||
}
|
||||
|
||||
public applyAngularImpulse(impulse: number) {
|
||||
|
||||
if (this.isDynamic == false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.isAwake == false)
|
||||
{
|
||||
this.awake(true);
|
||||
}
|
||||
|
||||
this.angularVelocity += impulse * this.inertiaInverted;
|
||||
|
||||
}
|
||||
|
||||
public kineticEnergy() {
|
||||
|
||||
var vsq = this.velocity.dot(this.velocity);
|
||||
var wsq = this.angularVelocity * this.angularVelocity;
|
||||
|
||||
return 0.5 * (this.mass * vsq + this.inertia * wsq);
|
||||
|
||||
}
|
||||
|
||||
public get isAwake(): bool {
|
||||
return this.awaked;
|
||||
}
|
||||
|
||||
public awake(flag) {
|
||||
|
||||
this.awaked = flag;
|
||||
|
||||
if (flag)
|
||||
{
|
||||
this.sleepTime = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.velocity.setTo(0, 0);
|
||||
this.angularVelocity = 0;
|
||||
this.force.setTo(0, 0);
|
||||
this.torque = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public isCollidable(other:Body) {
|
||||
|
||||
if (this == other)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.isDynamic == false && other.isDynamic == false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(this.maskBits & other.categoryBits) || !(other.maskBits & this.categoryBits))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (var i = 0; i < this.joints.length; i++)
|
||||
{
|
||||
var joint = this.joints[i];
|
||||
|
||||
if (!this.joints[i] || (!this.joints[i].collideConnected && other.jointHash[this.joints[i].id] != undefined))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
/// <reference path="../../../math/Vec2.ts" />
|
||||
/// <reference path="../../../geom/Point.ts" />
|
||||
/// <reference path="../../../math/Vec2Utils.ts" />
|
||||
/// <reference path="../../math/Vec2.ts" />
|
||||
/// <reference path="../../geom/Point.ts" />
|
||||
/// <reference path="../../math/Vec2Utils.ts" />
|
||||
/// <reference path="../Manager.ts" />
|
||||
/// <reference path="../Body.ts" />
|
||||
|
||||
|
@ -10,15 +10,15 @@
|
|||
* Based on the work Ju Hyung Lee started in JS PhyRus.
|
||||
*/
|
||||
|
||||
module Phaser.Physics.Advanced {
|
||||
module Phaser.Physics {
|
||||
|
||||
export interface IJoint {
|
||||
|
||||
id: number;
|
||||
type: number;
|
||||
|
||||
body1: Phaser.Physics.Advanced.Body;
|
||||
body2: Phaser.Physics.Advanced.Body;
|
||||
body1: Phaser.Physics.Body;
|
||||
body2: Phaser.Physics.Body;
|
||||
|
||||
collideConnected; // bool?
|
||||
maxForce: number;
|
|
@ -1,6 +1,6 @@
|
|||
/// <reference path="../../../math/Vec2.ts" />
|
||||
/// <reference path="../../../geom/Point.ts" />
|
||||
/// <reference path="../../../math/Vec2Utils.ts" />
|
||||
/// <reference path="../../math/Vec2.ts" />
|
||||
/// <reference path="../../geom/Point.ts" />
|
||||
/// <reference path="../../math/Vec2Utils.ts" />
|
||||
/// <reference path="../Manager.ts" />
|
||||
/// <reference path="../Body.ts" />
|
||||
|
||||
|
@ -10,13 +10,13 @@
|
|||
* Based on the work Ju Hyung Lee started in JS PhyRus.
|
||||
*/
|
||||
|
||||
module Phaser.Physics.Advanced {
|
||||
module Phaser.Physics {
|
||||
|
||||
export class Joint {
|
||||
|
||||
constructor(type: number, body1:Phaser.Physics.Advanced.Body, body2:Phaser.Physics.Advanced.Body, collideConnected) {
|
||||
constructor(type: number, body1:Phaser.Physics.Body, body2:Phaser.Physics.Body, collideConnected) {
|
||||
|
||||
this.id = Phaser.Physics.Advanced.Manager.jointCounter++;
|
||||
this.id = Phaser.Physics.Manager.jointCounter++;
|
||||
this.type = type;
|
||||
|
||||
this.body1 = body1;
|
||||
|
@ -32,8 +32,8 @@ module Phaser.Physics.Advanced {
|
|||
public id: number;
|
||||
public type: number;
|
||||
|
||||
public body1: Phaser.Physics.Advanced.Body;
|
||||
public body2: Phaser.Physics.Advanced.Body;
|
||||
public body1: Phaser.Physics.Body;
|
||||
public body2: Phaser.Physics.Body;
|
||||
|
||||
public collideConnected; // bool?
|
||||
public maxForce: number;
|
|
@ -1,4 +1,4 @@
|
|||
/// <reference path="../../../math/Vec2.ts" />
|
||||
/// <reference path="../../math/Vec2.ts" />
|
||||
/// <reference path="../Manager.ts" />
|
||||
/// <reference path="../Body.ts" />
|
||||
/// <reference path="Shape.ts" />
|
||||
|
@ -10,21 +10,27 @@
|
|||
* Based on the work Ju Hyung Lee started in JS PhyRus.
|
||||
*/
|
||||
|
||||
module Phaser.Physics.Advanced.Shapes {
|
||||
module Phaser.Physics.Shapes {
|
||||
|
||||
export class Box extends Phaser.Physics.Advanced.Shapes.Poly {
|
||||
export class Box extends Phaser.Physics.Shapes.Poly {
|
||||
|
||||
// Give in pixels
|
||||
constructor(x, y, width, height) {
|
||||
|
||||
//x = Manager.pixelsToMeters(x);
|
||||
//y = Manager.pixelsToMeters(y);
|
||||
//width = Manager.pixelsToMeters(width);
|
||||
//height = Manager.pixelsToMeters(height);
|
||||
console.log('Box px', x, y, width, height);
|
||||
|
||||
x = Manager.pixelsToMeters(x);
|
||||
y = Manager.pixelsToMeters(y);
|
||||
width = Manager.pixelsToMeters(width);
|
||||
height = Manager.pixelsToMeters(height);
|
||||
|
||||
console.log('Box m', x, y, width, height);
|
||||
|
||||
var hw = width * 0.5;
|
||||
var hh = height * 0.5;
|
||||
|
||||
console.log('Box hh', hw, hh);
|
||||
|
||||
super([
|
||||
{ x: -hw + x, y: +hh + y },
|
||||
{ x: -hw + x, y: -hh + y },
|
|
@ -1,5 +1,5 @@
|
|||
/// <reference path="../../../math/Vec2.ts" />
|
||||
/// <reference path="../../../math/Vec2Utils.ts" />
|
||||
/// <reference path="../../math/Vec2.ts" />
|
||||
/// <reference path="../../math/Vec2Utils.ts" />
|
||||
/// <reference path="../Manager.ts" />
|
||||
/// <reference path="../Body.ts" />
|
||||
/// <reference path="Shape.ts" />
|
||||
|
@ -10,9 +10,9 @@
|
|||
* Based on the work Ju Hyung Lee started in JS PhyRus.
|
||||
*/
|
||||
|
||||
module Phaser.Physics.Advanced.Shapes {
|
||||
module Phaser.Physics.Shapes {
|
||||
|
||||
export class Circle extends Phaser.Physics.Advanced.Shape implements IShape {
|
||||
export class Circle extends Phaser.Physics.Shape implements IShape {
|
||||
|
||||
constructor(radius: number, x?: number = 0, y?: number = 0) {
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
/// <reference path="../../../math/Vec2.ts" />
|
||||
/// <reference path="../../../geom/Point.ts" />
|
||||
/// <reference path="../../../math/Vec2Utils.ts" />
|
||||
/// <reference path="../../math/Vec2.ts" />
|
||||
/// <reference path="../../geom/Point.ts" />
|
||||
/// <reference path="../../math/Vec2Utils.ts" />
|
||||
/// <reference path="../Manager.ts" />
|
||||
/// <reference path="../Body.ts" />
|
||||
/// <reference path="Shape.ts" />
|
||||
|
@ -11,7 +11,7 @@
|
|||
* Based on the work Ju Hyung Lee started in JS PhyRus.
|
||||
*/
|
||||
|
||||
module Phaser.Physics.Advanced {
|
||||
module Phaser.Physics {
|
||||
|
||||
export interface IShape {
|
||||
|
||||
|
@ -33,10 +33,12 @@ module Phaser.Physics.Advanced {
|
|||
findEdgeByPoint(p: Phaser.Vec2, minDist: number): number;
|
||||
findVertexByPoint(p: Phaser.Vec2, minDist: number): number;
|
||||
|
||||
// The verts of the shape (in local coordinate space)
|
||||
verts: Phaser.Vec2[];
|
||||
planes: Phaser.Physics.Advanced.Plane[];
|
||||
planes: Phaser.Physics.Plane[];
|
||||
// The translated verts (in world space)
|
||||
tverts: Phaser.Vec2[];
|
||||
tplanes: Phaser.Physics.Advanced.Plane[];
|
||||
tplanes: Phaser.Physics.Plane[];
|
||||
convexity: bool;
|
||||
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/// <reference path="../../../math/Vec2.ts" />
|
||||
/// <reference path="../../../math/Vec2Utils.ts" />
|
||||
/// <reference path="../../math/Vec2.ts" />
|
||||
/// <reference path="../../math/Vec2Utils.ts" />
|
||||
/// <reference path="../Manager.ts" />
|
||||
/// <reference path="../Body.ts" />
|
||||
/// <reference path="../Plane.ts" />
|
||||
|
@ -11,9 +11,9 @@
|
|||
* Based on the work Ju Hyung Lee started in JS PhyRus.
|
||||
*/
|
||||
|
||||
module Phaser.Physics.Advanced.Shapes {
|
||||
module Phaser.Physics.Shapes {
|
||||
|
||||
export class Poly extends Phaser.Physics.Advanced.Shape implements IShape {
|
||||
export class Poly extends Phaser.Physics.Shape implements IShape {
|
||||
|
||||
// Verts is an optional array of objects, the objects must have public x and y properties which will be used
|
||||
// to seed this polygon (i.e. Vec2 objects, or just straight JS objects) and must wind COUNTER clockwise
|
||||
|
@ -33,7 +33,7 @@ module Phaser.Physics.Advanced.Shapes {
|
|||
this.verts[i] = new Phaser.Vec2(verts[i].x, verts[i].y);
|
||||
this.tverts[i] = this.verts[i];
|
||||
//this.tverts[i] = new Phaser.Vec2(verts[i].x, verts[i].y);
|
||||
this.tplanes[i] = new Phaser.Physics.Advanced.Plane(new Phaser.Vec2, 0);
|
||||
this.tplanes[i] = new Phaser.Physics.Plane(new Phaser.Vec2, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -62,12 +62,12 @@ module Phaser.Physics.Advanced.Shapes {
|
|||
var b = this.verts[(i + 1) % this.verts.length];
|
||||
var n = Phaser.Vec2Utils.normalize(Phaser.Vec2Utils.perp(Phaser.Vec2Utils.subtract(a, b)));
|
||||
|
||||
this.planes[i] = new Phaser.Physics.Advanced.Plane(n, Phaser.Vec2Utils.dot(n, a));
|
||||
this.planes[i] = new Phaser.Physics.Plane(n, Phaser.Vec2Utils.dot(n, a));
|
||||
|
||||
this.tverts[i] = Phaser.Vec2Utils.clone(this.verts[i]); // reference???
|
||||
//this.tverts[i] = this.verts[i]; // reference???
|
||||
|
||||
this.tplanes[i] = new Phaser.Physics.Advanced.Plane(new Phaser.Vec2, 0);
|
||||
this.tplanes[i] = new Phaser.Physics.Plane(new Phaser.Vec2, 0);
|
||||
}
|
||||
|
||||
for (var i = 0; i < this.verts.length; i++)
|
||||
|
@ -85,7 +85,7 @@ module Phaser.Physics.Advanced.Shapes {
|
|||
}
|
||||
|
||||
public duplicate() {
|
||||
return new Phaser.Physics.Advanced.Shapes.Poly(this.verts);
|
||||
return new Phaser.Physics.Shapes.Poly(this.verts);
|
||||
}
|
||||
|
||||
public recenter(c) {
|
|
@ -1,5 +1,5 @@
|
|||
/// <reference path="../../../math/Vec2.ts" />
|
||||
/// <reference path="../../../math/Vec2Utils.ts" />
|
||||
/// <reference path="../../math/Vec2.ts" />
|
||||
/// <reference path="../../math/Vec2Utils.ts" />
|
||||
/// <reference path="../Manager.ts" />
|
||||
/// <reference path="../Body.ts" />
|
||||
/// <reference path="Shape.ts" />
|
||||
|
@ -10,9 +10,9 @@
|
|||
* Based on the work Ju Hyung Lee started in JS PhyRus.
|
||||
*/
|
||||
|
||||
module Phaser.Physics.Advanced.Shapes {
|
||||
module Phaser.Physics.Shapes {
|
||||
|
||||
export class Segment extends Phaser.Physics.Advanced.Shape implements IShape {
|
||||
export class Segment extends Phaser.Physics.Shape implements IShape {
|
||||
|
||||
constructor(a, b, radius: number) {
|
||||
|
||||
|
@ -52,7 +52,7 @@ module Phaser.Physics.Advanced.Shapes {
|
|||
}
|
||||
|
||||
public duplicate() {
|
||||
return new Phaser.Physics.Advanced.Shapes.Segment(this.a, this.b, this.radius);
|
||||
return new Phaser.Physics.Shapes.Segment(this.a, this.b, this.radius);
|
||||
}
|
||||
|
||||
public recenter(c) {
|
|
@ -1,5 +1,5 @@
|
|||
/// <reference path="../../../math/Vec2.ts" />
|
||||
/// <reference path="../../../math/Vec2Utils.ts" />
|
||||
/// <reference path="../../math/Vec2.ts" />
|
||||
/// <reference path="../../math/Vec2Utils.ts" />
|
||||
/// <reference path="../Manager.ts" />
|
||||
/// <reference path="../Body.ts" />
|
||||
/// <reference path="../Bounds.ts" />
|
||||
|
@ -11,13 +11,13 @@
|
|||
* Based on the work Ju Hyung Lee started in JS PhyRus.
|
||||
*/
|
||||
|
||||
module Phaser.Physics.Advanced {
|
||||
module Phaser.Physics {
|
||||
|
||||
export class Shape {
|
||||
|
||||
constructor(type: number) {
|
||||
|
||||
this.id = Phaser.Physics.Advanced.Manager.shapeCounter++;
|
||||
this.id = Phaser.Physics.Manager.shapeCounter++;
|
||||
this.type = type;
|
||||
|
||||
this.elasticity = 0.0;
|
||||
|
@ -33,10 +33,10 @@ module Phaser.Physics.Advanced {
|
|||
public body: Body;
|
||||
|
||||
public verts: Phaser.Vec2[];
|
||||
public planes: Phaser.Physics.Advanced.Plane[];
|
||||
public planes: Phaser.Physics.Plane[];
|
||||
|
||||
public tverts: Phaser.Vec2[];
|
||||
public tplanes: Phaser.Physics.Advanced.Plane[];
|
||||
public tplanes: Phaser.Physics.Plane[];
|
||||
|
||||
public convexity: bool;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
/// <reference path="../../../math/Vec2.ts" />
|
||||
/// <reference path="../../math/Vec2.ts" />
|
||||
/// <reference path="../Manager.ts" />
|
||||
/// <reference path="../Body.ts" />
|
||||
/// <reference path="Shape.ts" />
|
||||
|
@ -10,9 +10,9 @@
|
|||
* Based on the work Ju Hyung Lee started in JS PhyRus.
|
||||
*/
|
||||
|
||||
module Phaser.Physics.Advanced.Shapes {
|
||||
module Phaser.Physics.Shapes {
|
||||
|
||||
export class Triangle extends Phaser.Physics.Advanced.Shapes.Poly {
|
||||
export class Triangle extends Phaser.Physics.Shapes.Poly {
|
||||
|
||||
constructor(x1: number, y1: number, x2: number, y2: number, x3: number, y3: number) {
|
||||
|
|
@ -124,7 +124,7 @@ module Phaser {
|
|||
|
||||
if (threshold >= 359 || threshold <= 0)
|
||||
{
|
||||
throw Error("FlxColor Warning: Invalid threshold given to getSplitComplementHarmony()");
|
||||
throw Error("ColorUtils Warning: Invalid threshold given to getSplitComplementHarmony()");
|
||||
}
|
||||
|
||||
var opposite: number = ColorUtils.game.math.wrapValue(hsv.hue, 180, 359);
|
||||
|
|
|
@ -17,6 +17,12 @@ module Phaser {
|
|||
|
||||
static game: Game;
|
||||
|
||||
/**
|
||||
* Render context of stage's canvas.
|
||||
* @type {CanvasRenderingContext2D}
|
||||
*/
|
||||
static context: CanvasRenderingContext2D;
|
||||
|
||||
/**
|
||||
* Render debug infos. (including name, bounds info, position and some other properties)
|
||||
* @param x {number} X position of the debug info to be rendered.
|
||||
|
@ -25,14 +31,48 @@ module Phaser {
|
|||
*/
|
||||
static renderSpriteInfo(sprite: Sprite, x: number, y: number, color?: string = 'rgb(255,255,255)') {
|
||||
|
||||
DebugUtils.game.stage.context.fillStyle = color;
|
||||
DebugUtils.game.stage.context.fillText('Sprite: ' + ' (' + sprite.width + ' x ' + sprite.height + ') origin: ' + sprite.transform.origin.x + ' x ' + sprite.transform.origin.y, x, y);
|
||||
DebugUtils.game.stage.context.fillText('x: ' + sprite.x.toFixed(1) + ' y: ' + sprite.y.toFixed(1) + ' rotation: ' + sprite.rotation.toFixed(1), x, y + 14);
|
||||
DebugUtils.game.stage.context.fillText('wx: ' + sprite.worldView.x + ' wy: ' + sprite.worldView.y + ' ww: ' + sprite.worldView.width.toFixed(1) + ' wh: ' + sprite.worldView.height.toFixed(1) + ' wb: ' + sprite.worldView.bottom + ' wr: ' + sprite.worldView.right, x, y + 28);
|
||||
DebugUtils.game.stage.context.fillText('sx: ' + sprite.transform.scale.x.toFixed(1) + ' sy: ' + sprite.transform.scale.y.toFixed(1), x, y + 42);
|
||||
DebugUtils.game.stage.context.fillText('tx: ' + sprite.texture.width.toFixed(1) + ' ty: ' + sprite.texture.height.toFixed(1), x, y + 56);
|
||||
DebugUtils.game.stage.context.fillText('cx: ' + sprite.cameraView.x + ' cy: ' + sprite.cameraView.y + ' cw: ' + sprite.cameraView.width + ' ch: ' + sprite.cameraView.height + ' cb: ' + sprite.cameraView.bottom + ' cr: ' + sprite.cameraView.right, x, y + 70);
|
||||
DebugUtils.game.stage.context.fillText('inCamera: ' + DebugUtils.game.renderer.inCamera(DebugUtils.game.camera, sprite), x, y + 84);
|
||||
DebugUtils.context.fillStyle = color;
|
||||
DebugUtils.context.fillText('Sprite: ' + ' (' + sprite.width + ' x ' + sprite.height + ') origin: ' + sprite.transform.origin.x + ' x ' + sprite.transform.origin.y, x, y);
|
||||
DebugUtils.context.fillText('x: ' + sprite.x.toFixed(1) + ' y: ' + sprite.y.toFixed(1) + ' rotation: ' + sprite.rotation.toFixed(1), x, y + 14);
|
||||
DebugUtils.context.fillText('wx: ' + sprite.worldView.x + ' wy: ' + sprite.worldView.y + ' ww: ' + sprite.worldView.width.toFixed(1) + ' wh: ' + sprite.worldView.height.toFixed(1) + ' wb: ' + sprite.worldView.bottom + ' wr: ' + sprite.worldView.right, x, y + 28);
|
||||
DebugUtils.context.fillText('sx: ' + sprite.transform.scale.x.toFixed(1) + ' sy: ' + sprite.transform.scale.y.toFixed(1), x, y + 42);
|
||||
DebugUtils.context.fillText('tx: ' + sprite.texture.width.toFixed(1) + ' ty: ' + sprite.texture.height.toFixed(1), x, y + 56);
|
||||
DebugUtils.context.fillText('cx: ' + sprite.cameraView.x + ' cy: ' + sprite.cameraView.y + ' cw: ' + sprite.cameraView.width + ' ch: ' + sprite.cameraView.height + ' cb: ' + sprite.cameraView.bottom + ' cr: ' + sprite.cameraView.right, x, y + 70);
|
||||
DebugUtils.context.fillText('inCamera: ' + DebugUtils.game.renderer.inCamera(DebugUtils.game.camera, sprite), x, y + 84);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
*/
|
||||
static renderPhysicsBodyInfo(body: Phaser.Physics.Body, x: number, y: number, color?: string = 'rgb(255,255,255)') {
|
||||
|
||||
DebugUtils.context.fillStyle = color;
|
||||
DebugUtils.context.fillText('Body ID: ' + body.name, x, y);
|
||||
DebugUtils.context.fillText('Position x: ' + body.position.x.toFixed(1) + ' y: ' + body.position.y.toFixed(1) + ' rotation: ' + body.angle.toFixed(1), x, y + 14);
|
||||
DebugUtils.context.fillText('World x: ' + (body.position.x * 50).toFixed(1) + ' y: ' + (body.position.y * 50).toFixed(1), x, y + 28);
|
||||
DebugUtils.context.fillText('Velocity x: ' + body.velocity.x.toFixed(1) + ' y: ' + body.velocity.y.toFixed(1), x, y + 42);
|
||||
|
||||
if (body.shapes[0].verts.length > 0)
|
||||
{
|
||||
|
||||
DebugUtils.context.fillText('Vert 1 x: ' + (body.shapes[0].verts[0].x * 50) + ' y: ' + (body.shapes[0].verts[0].y * 50), x, y + 56);
|
||||
DebugUtils.context.fillText('Vert 2 x: ' + (body.shapes[0].verts[1].x * 50) + ' y: ' + (body.shapes[0].verts[1].y * 50), x, y + 70);
|
||||
DebugUtils.context.fillText('Vert 3 x: ' + (body.shapes[0].tverts[2].x * 50) + ' y: ' + (body.shapes[0].tverts[2].y * 50), x, y + 84);
|
||||
DebugUtils.context.fillText('Vert 4 x: ' + (body.shapes[0].tverts[3].x * 50) + ' y: ' + (body.shapes[0].tverts[3].y * 50), x, y + 98);
|
||||
|
||||
|
||||
/*
|
||||
DebugUtils.context.fillText('Vert 1 x: ' + body.shapes[0].verts[0].x.toFixed(1) + ' y: ' + body.shapes[0].verts[0].y.toFixed(1), x, y + 56);
|
||||
DebugUtils.context.fillText('Vert 2 x: ' + body.shapes[0].verts[1].x.toFixed(1) + ' y: ' + body.shapes[0].verts[1].y.toFixed(1), x, y + 70);
|
||||
DebugUtils.context.fillText('Vert 3 x: ' + body.shapes[0].verts[2].x.toFixed(1) + ' y: ' + body.shapes[0].verts[2].y.toFixed(1), x, y + 84);
|
||||
DebugUtils.context.fillText('Vert 4 x: ' + body.shapes[0].verts[3].x.toFixed(1) + ' y: ' + body.shapes[0].verts[3].y.toFixed(1), x, y + 98);
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -43,29 +83,56 @@ module Phaser {
|
|||
camera = DebugUtils.game.camera;
|
||||
}
|
||||
|
||||
//var dx = (camera.screenView.x * sprite.transform.scrollFactor.x) + sprite.x - (camera.worldView.x * sprite.transform.scrollFactor.x);
|
||||
//var dy = (camera.screenView.y * sprite.transform.scrollFactor.y) + sprite.y - (camera.worldView.y * sprite.transform.scrollFactor.y);
|
||||
var dx = sprite.worldView.x;
|
||||
var dy = sprite.worldView.y;
|
||||
|
||||
DebugUtils.game.stage.context.fillStyle = color;
|
||||
DebugUtils.game.stage.context.fillRect(dx, dy, sprite.width, sprite.height);
|
||||
DebugUtils.context.fillStyle = color;
|
||||
DebugUtils.context.fillRect(dx, dy, sprite.width, sprite.height);
|
||||
|
||||
}
|
||||
|
||||
static renderSpritePhysicsBody(sprite: Sprite, camera?: Camera = null, color?: string = 'rgba(255,0,0,0.2)') {
|
||||
static renderPhysicsBody(body: Phaser.Physics.Body, lineWidth: number = 1, fillStyle: string = 'rgba(0,255,0,0.2)', sleepStyle: string = 'rgba(100,100,100,0.2)') {
|
||||
|
||||
if (camera == null)
|
||||
for (var s = 0; s < body.shapesLength; s++)
|
||||
{
|
||||
camera = DebugUtils.game.camera;
|
||||
DebugUtils.context.beginPath();
|
||||
|
||||
if (body.shapes[s].type == Phaser.Physics.Manager.SHAPE_TYPE_POLY)
|
||||
{
|
||||
var verts = body.shapes[s].tverts;
|
||||
|
||||
// DebugUtils.context.moveTo(body.position.x * 50 + verts[0].x, body.position.y * 50 + verts[0].y);
|
||||
DebugUtils.context.moveTo(verts[0].x * 50, verts[0].y * 50);
|
||||
|
||||
for (var i = 1; i < verts.length; i++) {
|
||||
// DebugUtils.context.lineTo(body.position.x * 50 + verts[i].x, body.position.y * 50 + verts[i].y);
|
||||
DebugUtils.context.lineTo(verts[i].x * 50, verts[i].y * 50);
|
||||
}
|
||||
|
||||
// DebugUtils.context.lineTo(body.position.x * 50 + verts[0].x, body.position.y * 50 + verts[0].y);
|
||||
DebugUtils.context.lineTo(verts[0].x * 50, verts[0].y * 50);
|
||||
}
|
||||
else if (body.shapes[s].type == Phaser.Physics.Manager.SHAPE_TYPE_CIRCLE)
|
||||
{
|
||||
var circle = <Phaser.Physics.Shapes.Circle> body.shapes[s];
|
||||
DebugUtils.context.arc(circle.tc.x * 50, circle.tc.y * 50, circle.radius * 50, 0, Math.PI * 2, false);
|
||||
}
|
||||
|
||||
DebugUtils.context.closePath();
|
||||
|
||||
if (body.isAwake)
|
||||
{
|
||||
DebugUtils.context.fillStyle = fillStyle;
|
||||
}
|
||||
else
|
||||
{
|
||||
DebugUtils.context.fillStyle = sleepStyle;
|
||||
}
|
||||
|
||||
DebugUtils.context.fill();
|
||||
|
||||
}
|
||||
|
||||
var dx = (camera.screenView.x * sprite.transform.scrollFactor.x) + sprite.body.x - (camera.worldView.x * sprite.transform.scrollFactor.x);
|
||||
var dy = (camera.screenView.y * sprite.transform.scrollFactor.y) + sprite.body.y - (camera.worldView.y * sprite.transform.scrollFactor.y);
|
||||
|
||||
DebugUtils.game.stage.context.fillStyle = color;
|
||||
DebugUtils.game.stage.context.fillRect(dx, dy, sprite.body.width, sprite.body.height);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -272,8 +272,8 @@ module Phaser {
|
|||
static reset(sprite: Sprite, x: number, y: number) {
|
||||
|
||||
sprite.revive();
|
||||
sprite.body.touching = Types.NONE;
|
||||
sprite.body.wasTouching = Types.NONE;
|
||||
//sprite.body.touching = Types.NONE;
|
||||
//sprite.body.wasTouching = Types.NONE;
|
||||
sprite.x = x;
|
||||
sprite.y = y;
|
||||
sprite.body.velocity.x = 0;
|
||||
|
|
17
README.md
17
README.md
|
@ -41,14 +41,20 @@ TODO:
|
|||
* Add clip support + shape options to Texture Component.
|
||||
* Make sure I'm using Point and not Vec2 when it's not a directional vector I need
|
||||
* Bug with setting scale or anything on a Sprite inside a Group, or maybe group.addNewSprite issue
|
||||
|
||||
* Drag Sprite with "snap to center" uses local coords not world, so fails on scrolling world (no center lock works fine)
|
||||
* Need to be able to set the current tilemap layer, then the getTileXY default layer uses that one if no other given
|
||||
* Pointer worldX/Y don't appear to be correct for some reason
|
||||
* Create a Pixel game object type (useful for particles / fx)
|
||||
* Sprite collision events
|
||||
* See which functions in the input component can move elsewhere (utils)
|
||||
* Move all of the renderDebugInfo methods to the DebugUtils class
|
||||
* Check bounds/edge points when sprite is only 1x1 sized :)
|
||||
|
||||
* See what I can move out of Body and into a BodyUtils class.
|
||||
* See about optimising Advanced Physics a lot more, so it doesn't create lots of Vec2s everywhere.
|
||||
* QuadTree.physics.checkHullIntersection
|
||||
* Fix the Motion methods for the new physics system
|
||||
* Moved findShapeByPoint etc from Space to Manager (or at least add a proxy to them)
|
||||
|
||||
|
||||
V1.0.0
|
||||
|
||||
|
@ -67,7 +73,7 @@ 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
|
||||
* Removed Sprite.angle - use Sprite.rotation 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.
|
||||
* Added SpriteUtils.setOriginToCenter to quickly set the origin of a sprite based on either frameBounds or body.bounds
|
||||
|
@ -79,7 +85,7 @@ V1.0.0
|
|||
* Added Group.addNewSprite(x,y,key) for quick addition of new Sprites to a Group
|
||||
* Fixed Group.sort so the sortHandler is called correctly
|
||||
* Added Group.swap(a,b) to swap the z-index of 2 objects with optional rendering update boolean
|
||||
* Sprites dispatch killed/revived and added to and removed from Group events.
|
||||
* Sprites dispatch new events for: killed, revived, added to Group and removed from Group.
|
||||
* Added Input drag, bounds, sprite bounds and snapping support.
|
||||
* Added the new ColorUtils class full of lots of handy color manipulation functions.
|
||||
* Fixed issue in Camera.inCamera check where it wouldn't take into consideration the Sprites scrollFactor.
|
||||
|
@ -117,6 +123,9 @@ V1.0.0
|
|||
* Added Cache.getImageKeys (and similar) to return an array of all the keys for all currently cached objects.
|
||||
* Added Group.bringToTop feature. Will sort the Group, move the given sprites z-index to the top and shift the rest down by one.
|
||||
* Brand new Advanced Physics system added and working! Woohoo :)
|
||||
* Fixed issue in Tilemap.parseTiledJSON where it would accidentally think image and object layers were map data.
|
||||
* Fixed bug in Group.bringToTop if the child didn't have a group property yet.
|
||||
* Fixed bug in FrameData.checkFrameName where the first index of the _frameNames array would be skipped.
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -65,7 +65,6 @@
|
|||
<Content Include="cameras\scrollfactor 2.js">
|
||||
<DependentUpon>scrollfactor 2.ts</DependentUpon>
|
||||
</Content>
|
||||
<TypeScriptCompile Include="physics\aabb 1.ts" />
|
||||
<TypeScriptCompile Include="particles\graphic emitter.ts" />
|
||||
<TypeScriptCompile Include="input\over sprite 1.ts" />
|
||||
<TypeScriptCompile Include="groups\create group 1.ts" />
|
||||
|
@ -174,25 +173,14 @@
|
|||
<Content Include="particles\when particles collide.js">
|
||||
<DependentUpon>when particles collide.ts</DependentUpon>
|
||||
</Content>
|
||||
<Content Include="physics\aabb 1.js">
|
||||
<DependentUpon>aabb 1.ts</DependentUpon>
|
||||
</Content>
|
||||
<TypeScriptCompile Include="scrollzones\simple scrollzone.ts" />
|
||||
<TypeScriptCompile Include="scrollzones\scroll window.ts" />
|
||||
<TypeScriptCompile Include="scrollzones\region demo.ts" />
|
||||
<TypeScriptCompile Include="scrollzones\parallax.ts" />
|
||||
<TypeScriptCompile Include="scrollzones\ballscroller.ts" />
|
||||
<TypeScriptCompile Include="physics\aabb vs aabb 1.ts" />
|
||||
<Content Include="physics\aabb vs aabb 1.js">
|
||||
<DependentUpon>aabb vs aabb 1.ts</DependentUpon>
|
||||
</Content>
|
||||
<TypeScriptCompile Include="physics\obb vs obb.ts" />
|
||||
<TypeScriptCompile Include="physics\body1.ts" />
|
||||
<Content Include="physics\body1.js">
|
||||
<DependentUpon>body1.ts</DependentUpon>
|
||||
</Content>
|
||||
<Content Include="physics\obb vs obb.js">
|
||||
<DependentUpon>obb vs obb.ts</DependentUpon>
|
||||
<TypeScriptCompile Include="physics\simple test 1.ts" />
|
||||
<Content Include="physics\simple test 1.js">
|
||||
<DependentUpon>simple test 1.ts</DependentUpon>
|
||||
</Content>
|
||||
<Content Include="scrollzones\ballscroller.js">
|
||||
<DependentUpon>ballscroller.ts</DependentUpon>
|
||||
|
|
|
@ -12,9 +12,6 @@
|
|||
function create() {
|
||||
game.add.sprite(0, 0, 'backdrop');
|
||||
ball = game.add.sprite(200, 200, 'ball');
|
||||
ball.body.offset.setTo(-16, -16);
|
||||
ball.body.width = 100;
|
||||
ball.body.height = 100;
|
||||
ball.body.velocity.x = 50;
|
||||
ball.transform.scale.setTo(2, 2);
|
||||
}
|
||||
|
@ -56,7 +53,5 @@
|
|||
function render() {
|
||||
game.camera.renderDebugInfo(32, 32);
|
||||
Phaser.DebugUtils.renderSpriteInfo(ball, 32, 200);
|
||||
//Phaser.DebugUtils.renderSpriteBounds(ball);
|
||||
Phaser.DebugUtils.renderSpritePhysicsBody(ball);
|
||||
}
|
||||
})();
|
||||
|
|
|
@ -24,10 +24,6 @@
|
|||
|
||||
ball = game.add.sprite(200, 200, 'ball');
|
||||
|
||||
ball.body.offset.setTo(-16, -16);
|
||||
ball.body.width = 100;
|
||||
ball.body.height = 100;
|
||||
|
||||
ball.body.velocity.x = 50;
|
||||
ball.transform.scale.setTo(2, 2);
|
||||
|
||||
|
@ -83,8 +79,6 @@
|
|||
|
||||
game.camera.renderDebugInfo(32, 32);
|
||||
Phaser.DebugUtils.renderSpriteInfo(ball, 32, 200);
|
||||
//Phaser.DebugUtils.renderSpriteBounds(ball);
|
||||
Phaser.DebugUtils.renderSpritePhysicsBody(ball);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -33,7 +33,6 @@
|
|||
}
|
||||
function render() {
|
||||
game.camera.renderDebugInfo(32, 32);
|
||||
test.body.renderDebugInfo(300, 32);
|
||||
Phaser.DebugUtils.renderSpriteInfo(test, 32, 200);
|
||||
game.input.renderDebugInfo(300, 200);
|
||||
}
|
||||
|
|
|
@ -62,8 +62,6 @@
|
|||
|
||||
game.camera.renderDebugInfo(32, 32);
|
||||
|
||||
test.body.renderDebugInfo(300, 32);
|
||||
|
||||
Phaser.DebugUtils.renderSpriteInfo(test, 32, 200);
|
||||
|
||||
game.input.renderDebugInfo(300, 200);
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
var Phaser;
|
||||
(function (Phaser) {
|
||||
(function (FX) {
|
||||
/// <reference path="../../build/phaser.d.ts" />
|
||||
/**
|
||||
* Phaser - FX - Camera - Flash
|
||||
*
|
||||
* The camera is filled with the given color and returns to normal at the given duration.
|
||||
*/
|
||||
(function (Camera) {
|
||||
var Flash = (function () {
|
||||
function Flash(game) {
|
||||
|
@ -15,21 +9,12 @@ var Phaser;
|
|||
this._fxFlashAlpha = 0;
|
||||
this._game = game;
|
||||
}
|
||||
Flash.prototype.start = /**
|
||||
* The camera is filled with this color and returns to normal at the given duration.
|
||||
*
|
||||
* @param Color The color you want to use in 0xRRGGBB format, i.e. 0xffffff for white.
|
||||
* @param Duration How long it takes for the flash to fade.
|
||||
* @param OnComplete An optional function you want to run when the flash finishes. Set to null for no callback.
|
||||
* @param Force Force an already running flash effect to reset.
|
||||
*/
|
||||
function (color, duration, onComplete, force) {
|
||||
Flash.prototype.start = function (color, duration, onComplete, force) {
|
||||
if (typeof color === "undefined") { color = 0xffffff; }
|
||||
if (typeof duration === "undefined") { duration = 1; }
|
||||
if (typeof onComplete === "undefined") { onComplete = null; }
|
||||
if (typeof force === "undefined") { force = false; }
|
||||
if(force === false && this._fxFlashAlpha > 0) {
|
||||
// You can't flash again unless you force it
|
||||
return;
|
||||
}
|
||||
if(duration <= 0) {
|
||||
|
@ -44,7 +29,6 @@ var Phaser;
|
|||
this._fxFlashComplete = onComplete;
|
||||
};
|
||||
Flash.prototype.postUpdate = function () {
|
||||
// Update the Flash effect
|
||||
if(this._fxFlashAlpha > 0) {
|
||||
this._fxFlashAlpha -= this._game.time.elapsed / this._fxFlashDuration;
|
||||
if(this._game.math.roundTo(this._fxFlashAlpha, -2) <= 0) {
|
||||
|
@ -72,38 +56,17 @@ var Phaser;
|
|||
var Phaser;
|
||||
(function (Phaser) {
|
||||
(function (FX) {
|
||||
/// <reference path="../../build/phaser.d.ts" />
|
||||
/**
|
||||
* Phaser - FX - Camera - Border
|
||||
*
|
||||
* Creates a border around a camera.
|
||||
*/
|
||||
(function (Camera) {
|
||||
var Border = (function () {
|
||||
function Border(game, parent) {
|
||||
/**
|
||||
* Whether render border of this camera or not. (default is false)
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.showBorder = false;
|
||||
/**
|
||||
* Color of border of this camera. (in css color string)
|
||||
* @type {string}
|
||||
*/
|
||||
this.borderColor = 'rgb(255,255,255)';
|
||||
this._game = game;
|
||||
this._parent = parent;
|
||||
}
|
||||
Border.prototype.start = /**
|
||||
* You can name the function that starts the effect whatever you like, but we used 'start' in our effects.
|
||||
*/
|
||||
function () {
|
||||
Border.prototype.start = function () {
|
||||
};
|
||||
Border.prototype.postRender = /**
|
||||
* Post-render is called during the objects render cycle, after the children/image data has been rendered.
|
||||
* It happens directly BEFORE a canvas context.restore has happened if added to a Camera.
|
||||
*/
|
||||
function (camera, cameraX, cameraY, cameraWidth, cameraHeight) {
|
||||
Border.prototype.postRender = function (camera, cameraX, cameraY, cameraWidth, cameraHeight) {
|
||||
if(this.showBorder == true) {
|
||||
this._game.stage.context.strokeStyle = this.borderColor;
|
||||
this._game.stage.context.lineWidth = 1;
|
||||
|
@ -122,50 +85,23 @@ var Phaser;
|
|||
var Phaser;
|
||||
(function (Phaser) {
|
||||
(function (FX) {
|
||||
/// <reference path="../../build/phaser.d.ts" />
|
||||
/**
|
||||
* Phaser - FX - Camera - Template
|
||||
*
|
||||
* A Template FX file you can use to create your own Camera FX.
|
||||
* If you don't use any of the methods below (i.e. preUpdate, render, etc) then DELETE THEM to avoid un-necessary calls by the FXManager.
|
||||
*/
|
||||
(function (Camera) {
|
||||
var Template = (function () {
|
||||
function Template(game, parent) {
|
||||
this._game = game;
|
||||
this._parent = parent;
|
||||
}
|
||||
Template.prototype.start = /**
|
||||
* You can name the function that starts the effect whatever you like, but we used 'start' in our effects.
|
||||
*/
|
||||
function () {
|
||||
Template.prototype.start = function () {
|
||||
};
|
||||
Template.prototype.preUpdate = /**
|
||||
* Pre-update is called at the start of the objects update cycle, before any other updates have taken place.
|
||||
*/
|
||||
function () {
|
||||
Template.prototype.preUpdate = function () {
|
||||
};
|
||||
Template.prototype.postUpdate = /**
|
||||
* Post-update is called at the end of the objects update cycle, after other update logic has taken place.
|
||||
*/
|
||||
function () {
|
||||
Template.prototype.postUpdate = function () {
|
||||
};
|
||||
Template.prototype.preRender = /**
|
||||
* Pre-render is called at the start of the object render cycle, before any transforms have taken place.
|
||||
* It happens directly AFTER a canvas context.save has happened if added to a Camera.
|
||||
*/
|
||||
function (camera, cameraX, cameraY, cameraWidth, cameraHeight) {
|
||||
Template.prototype.preRender = function (camera, cameraX, cameraY, cameraWidth, cameraHeight) {
|
||||
};
|
||||
Template.prototype.render = /**
|
||||
* render is called during the objects render cycle, right after all transforms have finished, but before any children/image data is rendered.
|
||||
*/
|
||||
function (camera, cameraX, cameraY, cameraWidth, cameraHeight) {
|
||||
Template.prototype.render = function (camera, cameraX, cameraY, cameraWidth, cameraHeight) {
|
||||
};
|
||||
Template.prototype.postRender = /**
|
||||
* Post-render is called during the objects render cycle, after the children/image data has been rendered.
|
||||
* It happens directly BEFORE a canvas context.restore has happened if added to a Camera.
|
||||
*/
|
||||
function (camera, cameraX, cameraY, cameraWidth, cameraHeight) {
|
||||
Template.prototype.postRender = function (camera, cameraX, cameraY, cameraWidth, cameraHeight) {
|
||||
};
|
||||
return Template;
|
||||
})();
|
||||
|
@ -178,13 +114,6 @@ var Phaser;
|
|||
var Phaser;
|
||||
(function (Phaser) {
|
||||
(function (FX) {
|
||||
/// <reference path="../../build/phaser.d.ts" />
|
||||
/**
|
||||
* Phaser - FX - Camera - Mirror
|
||||
*
|
||||
* Creates a mirror effect for a camera.
|
||||
* Can mirror the camera image horizontally, vertically or both with an optional fill color overlay.
|
||||
*/
|
||||
(function (Camera) {
|
||||
var Mirror = (function () {
|
||||
function Mirror(game, parent) {
|
||||
|
@ -199,11 +128,7 @@ var Phaser;
|
|||
this._canvas.height = parent.height;
|
||||
this._context = this._canvas.getContext('2d');
|
||||
}
|
||||
Mirror.prototype.start = /**
|
||||
* This is the rectangular region to grab from the Camera used in the Mirror effect
|
||||
* It is rendered to the Stage at Mirror.x/y (note the use of Stage coordinates, not World coordinates)
|
||||
*/
|
||||
function (x, y, region, fillColor) {
|
||||
Mirror.prototype.start = function (x, y, region, fillColor) {
|
||||
if (typeof fillColor === "undefined") { fillColor = 'rgba(0, 0, 100, 0.5)'; }
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
|
@ -216,15 +141,7 @@ var Phaser;
|
|||
this._context.fillStyle = this._mirrorColor;
|
||||
}
|
||||
};
|
||||
Mirror.prototype.postRender = /**
|
||||
* Post-render is called during the objects render cycle, after the children/image data has been rendered.
|
||||
* It happens directly BEFORE a canvas context.restore has happened if added to a Camera.
|
||||
*/
|
||||
function (camera, cameraX, cameraY, cameraWidth, cameraHeight) {
|
||||
//if (this.cls)
|
||||
//{
|
||||
// this._context.clearRect(0, 0, this._mirrorWidth, this._mirrorHeight);
|
||||
//}
|
||||
Mirror.prototype.postRender = function (camera, cameraX, cameraY, cameraWidth, cameraHeight) {
|
||||
this._sx = cameraX + this._mirrorX;
|
||||
this._sy = cameraY + this._mirrorY;
|
||||
if(this.flipX == true && this.flipY == false) {
|
||||
|
@ -232,16 +149,7 @@ var Phaser;
|
|||
} else if(this.flipY == true && this.flipX == false) {
|
||||
this._sy = 0;
|
||||
}
|
||||
this._context.drawImage(this._game.stage.canvas, // Source Image
|
||||
this._sx, // Source X (location within the source image)
|
||||
this._sy, // Source Y
|
||||
this._mirrorWidth, // Source Width
|
||||
this._mirrorHeight, // Source Height
|
||||
0, // Destination X (where on the canvas it'll be drawn)
|
||||
0, // Destination Y
|
||||
this._mirrorWidth, // Destination Width (always same as Source Width unless scaled)
|
||||
this._mirrorHeight);
|
||||
// Destination Height (always same as Source Height unless scaled)
|
||||
this._context.drawImage(this._game.stage.canvas, this._sx, this._sy, this._mirrorWidth, this._mirrorHeight, 0, 0, this._mirrorWidth, this._mirrorHeight);
|
||||
if(this._mirrorColor) {
|
||||
this._context.fillRect(0, 0, this._mirrorWidth, this._mirrorHeight);
|
||||
}
|
||||
|
@ -267,49 +175,19 @@ var Phaser;
|
|||
var Phaser;
|
||||
(function (Phaser) {
|
||||
(function (FX) {
|
||||
/// <reference path="../../build/phaser.d.ts" />
|
||||
/**
|
||||
* Phaser - FX - Camera - Shadow
|
||||
*
|
||||
* Creates a drop-shadow effect on the camera window.
|
||||
*/
|
||||
(function (Camera) {
|
||||
var Shadow = (function () {
|
||||
function Shadow(game, parent) {
|
||||
/**
|
||||
* Render camera shadow or not. (default is false)
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.showShadow = false;
|
||||
/**
|
||||
* Color of shadow, in css color string.
|
||||
* @type {string}
|
||||
*/
|
||||
this.shadowColor = 'rgb(0,0,0)';
|
||||
/**
|
||||
* Blur factor of shadow.
|
||||
* @type {number}
|
||||
*/
|
||||
this.shadowBlur = 10;
|
||||
/**
|
||||
* Offset of the shadow from camera's position.
|
||||
* @type {Point}
|
||||
*/
|
||||
this.shadowOffset = new Phaser.Point(4, 4);
|
||||
this._game = game;
|
||||
this._parent = parent;
|
||||
}
|
||||
Shadow.prototype.start = /**
|
||||
* You can name the function that starts the effect whatever you like, but we used 'start' in our effects.
|
||||
*/
|
||||
function () {
|
||||
Shadow.prototype.start = function () {
|
||||
};
|
||||
Shadow.prototype.preRender = /**
|
||||
* Pre-render is called at the start of the object render cycle, before any transforms have taken place.
|
||||
* It happens directly AFTER a canvas context.save has happened if added to a Camera.
|
||||
*/
|
||||
function (camera, cameraX, cameraY, cameraWidth, cameraHeight) {
|
||||
// Shadow
|
||||
Shadow.prototype.preRender = function (camera, cameraX, cameraY, cameraWidth, cameraHeight) {
|
||||
if(this.showShadow == true) {
|
||||
this._game.stage.context.shadowColor = this.shadowColor;
|
||||
this._game.stage.context.shadowBlur = this.shadowBlur;
|
||||
|
@ -317,11 +195,7 @@ var Phaser;
|
|||
this._game.stage.context.shadowOffsetY = this.shadowOffset.y;
|
||||
}
|
||||
};
|
||||
Shadow.prototype.render = /**
|
||||
* render is called during the objects render cycle, right after all transforms have finished, but before any children/image data is rendered.
|
||||
*/
|
||||
function (camera, cameraX, cameraY, cameraWidth, cameraHeight) {
|
||||
// Shadow off
|
||||
Shadow.prototype.render = function (camera, cameraX, cameraY, cameraWidth, cameraHeight) {
|
||||
if(this.showShadow == true) {
|
||||
this._game.stage.context.shadowBlur = 0;
|
||||
this._game.stage.context.shadowOffsetX = 0;
|
||||
|
@ -339,12 +213,6 @@ var Phaser;
|
|||
var Phaser;
|
||||
(function (Phaser) {
|
||||
(function (FX) {
|
||||
/// <reference path="../../build/phaser.d.ts" />
|
||||
/**
|
||||
* Phaser - FX - Camera - Scanlines
|
||||
*
|
||||
* Give your game that classic retro feel!
|
||||
*/
|
||||
(function (Camera) {
|
||||
var Scanlines = (function () {
|
||||
function Scanlines(game, parent) {
|
||||
|
@ -370,12 +238,6 @@ var Phaser;
|
|||
var Phaser;
|
||||
(function (Phaser) {
|
||||
(function (FX) {
|
||||
/// <reference path="../../build/phaser.d.ts" />
|
||||
/**
|
||||
* Phaser - FX - Camera - Shake
|
||||
*
|
||||
* A simple camera shake effect.
|
||||
*/
|
||||
(function (Camera) {
|
||||
var Shake = (function () {
|
||||
function Shake(game, camera) {
|
||||
|
@ -392,16 +254,7 @@ var Phaser;
|
|||
Shake.SHAKE_BOTH_AXES = 0;
|
||||
Shake.SHAKE_HORIZONTAL_ONLY = 1;
|
||||
Shake.SHAKE_VERTICAL_ONLY = 2;
|
||||
Shake.prototype.start = /**
|
||||
* A simple camera shake effect.
|
||||
*
|
||||
* @param Intensity Percentage of screen size representing the maximum distance that the screen can move while shaking.
|
||||
* @param Duration The length in seconds that the shaking effect should last.
|
||||
* @param OnComplete A function you want to run when the shake effect finishes.
|
||||
* @param Force Force the effect to reset (default = true, unlike flash() and fade()!).
|
||||
* @param Direction Whether to shake on both axes, just up and down, or just side to side (use class constants SHAKE_BOTH_AXES, SHAKE_VERTICAL_ONLY, or SHAKE_HORIZONTAL_ONLY).
|
||||
*/
|
||||
function (intensity, duration, onComplete, force, direction) {
|
||||
Shake.prototype.start = function (intensity, duration, onComplete, force, direction) {
|
||||
if (typeof intensity === "undefined") { intensity = 0.05; }
|
||||
if (typeof duration === "undefined") { duration = 0.5; }
|
||||
if (typeof onComplete === "undefined") { onComplete = null; }
|
||||
|
@ -410,7 +263,6 @@ var Phaser;
|
|||
if(!force && ((this._fxShakeOffset.x != 0) || (this._fxShakeOffset.y != 0))) {
|
||||
return;
|
||||
}
|
||||
// If a shake is not already running we need to store the offsets here
|
||||
if(this._fxShakeOffset.x == 0 && this._fxShakeOffset.y == 0) {
|
||||
this._fxShakePrevX = this._parent.x;
|
||||
this._fxShakePrevY = this._parent.y;
|
||||
|
@ -422,7 +274,6 @@ var Phaser;
|
|||
this._fxShakeOffset.setTo(0, 0);
|
||||
};
|
||||
Shake.prototype.postUpdate = function () {
|
||||
// Update the "shake" special effect
|
||||
if(this._fxShakeDuration > 0) {
|
||||
this._fxShakeDuration -= this._game.time.elapsed;
|
||||
if(this._game.math.roundTo(this._fxShakeDuration, -2) <= 0) {
|
||||
|
@ -435,11 +286,9 @@ var Phaser;
|
|||
}
|
||||
} else {
|
||||
if((this._fxShakeDirection == Shake.SHAKE_BOTH_AXES) || (this._fxShakeDirection == Shake.SHAKE_HORIZONTAL_ONLY)) {
|
||||
//this._fxShakeOffset.x = ((this._game.math.random() * this._fxShakeIntensity * this.worldView.width * 2 - this._fxShakeIntensity * this.worldView.width) * this._zoom;
|
||||
this._fxShakeOffset.x = (this._game.math.random() * this._fxShakeIntensity * this._parent.worldView.width * 2 - this._fxShakeIntensity * this._parent.worldView.width);
|
||||
}
|
||||
if((this._fxShakeDirection == Shake.SHAKE_BOTH_AXES) || (this._fxShakeDirection == Shake.SHAKE_VERTICAL_ONLY)) {
|
||||
//this._fxShakeOffset.y = (this._game.math.random() * this._fxShakeIntensity * this.worldView.height * 2 - this._fxShakeIntensity * this.worldView.height) * this._zoom;
|
||||
this._fxShakeOffset.y = (this._game.math.random() * this._fxShakeIntensity * this._parent.worldView.height * 2 - this._fxShakeIntensity * this._parent.worldView.height);
|
||||
}
|
||||
}
|
||||
|
@ -462,12 +311,6 @@ var Phaser;
|
|||
var Phaser;
|
||||
(function (Phaser) {
|
||||
(function (FX) {
|
||||
/// <reference path="../../build/phaser.d.ts" />
|
||||
/**
|
||||
* Phaser - FX - Camera - Fade
|
||||
*
|
||||
* The camera is filled with the given color and returns to normal at the given duration.
|
||||
*/
|
||||
(function (Camera) {
|
||||
var Fade = (function () {
|
||||
function Fade(game) {
|
||||
|
@ -476,21 +319,12 @@ var Phaser;
|
|||
this._fxFadeAlpha = 0;
|
||||
this._game = game;
|
||||
}
|
||||
Fade.prototype.start = /**
|
||||
* The camera is gradually filled with this color.
|
||||
*
|
||||
* @param Color The color you want to use in 0xRRGGBB format, i.e. 0xffffff for white.
|
||||
* @param Duration How long it takes for the flash to fade.
|
||||
* @param OnComplete An optional function you want to run when the flash finishes. Set to null for no callback.
|
||||
* @param Force Force an already running flash effect to reset.
|
||||
*/
|
||||
function (color, duration, onComplete, force) {
|
||||
Fade.prototype.start = function (color, duration, onComplete, force) {
|
||||
if (typeof color === "undefined") { color = 0x000000; }
|
||||
if (typeof duration === "undefined") { duration = 1; }
|
||||
if (typeof onComplete === "undefined") { onComplete = null; }
|
||||
if (typeof force === "undefined") { force = false; }
|
||||
if(force === false && this._fxFadeAlpha > 0) {
|
||||
// You can't fade again unless you force it
|
||||
return;
|
||||
}
|
||||
if(duration <= 0) {
|
||||
|
@ -505,7 +339,6 @@ var Phaser;
|
|||
this._fxFadeComplete = onComplete;
|
||||
};
|
||||
Fade.prototype.postUpdate = function () {
|
||||
// Update the Fade effect
|
||||
if(this._fxFadeAlpha > 0) {
|
||||
this._fxFadeAlpha += this._game.time.elapsed / this._fxFadeDuration;
|
||||
if(this._game.math.roundTo(this._fxFadeAlpha, -2) >= 1) {
|
||||
|
@ -517,7 +350,6 @@ var Phaser;
|
|||
}
|
||||
};
|
||||
Fade.prototype.postRender = function (camera, cameraX, cameraY, cameraWidth, cameraHeight) {
|
||||
// "Fade" FX
|
||||
if(this._fxFadeAlpha > 0) {
|
||||
this._game.stage.context.fillStyle = this._fxFadeColor + this._fxFadeAlpha + ')';
|
||||
this._game.stage.context.fillRect(cameraX, cameraY, cameraWidth, cameraHeight);
|
||||
|
|
8680
Tests/phaser.js
8680
Tests/phaser.js
File diff suppressed because it is too large
Load diff
|
@ -18,13 +18,6 @@
|
|||
var walls;
|
||||
var t;
|
||||
function create() {
|
||||
//debug = <HTMLTextAreaElement> document.createElement('textarea');
|
||||
//debug.style.position = 'absolute';
|
||||
//debug.style.left = '850px';
|
||||
//debug.style.top = '32px';
|
||||
//debug.style.width = '600px';
|
||||
//debug.style.height = '600px';
|
||||
//document.body.appendChild(debug);
|
||||
//atari = game.add.sprite(200, 100, 'atari');
|
||||
// need to get the physics bounds around the sprite center, regardless of origin
|
||||
//atari.transform.origin.setTo(0.5, 0.5);
|
||||
|
|
|
@ -26,14 +26,6 @@
|
|||
|
||||
function create() {
|
||||
|
||||
//debug = <HTMLTextAreaElement> document.createElement('textarea');
|
||||
//debug.style.position = 'absolute';
|
||||
//debug.style.left = '850px';
|
||||
//debug.style.top = '32px';
|
||||
//debug.style.width = '600px';
|
||||
//debug.style.height = '600px';
|
||||
//document.body.appendChild(debug);
|
||||
|
||||
//atari = game.add.sprite(200, 100, 'atari');
|
||||
|
||||
// need to get the physics bounds around the sprite center, regardless of origin
|
||||
|
|
21
Tests/physics/simple test 1.js
Normal file
21
Tests/physics/simple test 1.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
(function () {
|
||||
var game = new Phaser.Game(this, 'game', 800, 600, init, create, null, render);
|
||||
function init() {
|
||||
game.load.image('atari', 'assets/sprites/atari130xe.png');
|
||||
game.load.image('ball', 'assets/sprites/shinyball.png');
|
||||
game.load.start();
|
||||
}
|
||||
var atari;
|
||||
var ball;
|
||||
function create() {
|
||||
game.physics.gravity.setTo(0, 5);
|
||||
atari = game.add.physicsSprite(300, 450, 'atari', null, Phaser.Types.BODY_STATIC);
|
||||
ball = game.add.physicsSprite(300 - 20, 0, 'ball');
|
||||
}
|
||||
function render() {
|
||||
Phaser.DebugUtils.renderPhysicsBodyInfo(atari.body, 32, 32);
|
||||
Phaser.DebugUtils.renderPhysicsBodyInfo(ball.body, 320, 32);
|
||||
Phaser.DebugUtils.renderPhysicsBody(atari.body);
|
||||
Phaser.DebugUtils.renderPhysicsBody(ball.body);
|
||||
}
|
||||
})();
|
45
Tests/physics/simple test 1.ts
Normal file
45
Tests/physics/simple test 1.ts
Normal file
|
@ -0,0 +1,45 @@
|
|||
/// <reference path="../../Phaser/Game.ts" />
|
||||
|
||||
(function () {
|
||||
|
||||
var game = new Phaser.Game(this, 'game', 800, 600, init, create, null, render);
|
||||
|
||||
function init() {
|
||||
|
||||
// Using Phasers asset loader we load up a PNG from the assets folder
|
||||
game.load.image('atari', 'assets/sprites/atari130xe.png');
|
||||
game.load.image('ball', 'assets/sprites/shinyball.png');
|
||||
game.load.start();
|
||||
|
||||
}
|
||||
|
||||
var atari: Phaser.Sprite;
|
||||
var ball: Phaser.Sprite;
|
||||
|
||||
function create() {
|
||||
|
||||
// Add some gravity to the world, otherwise nothing will actually happen
|
||||
game.physics.gravity.setTo(0, 5);
|
||||
|
||||
// We'll make the atari sprite a static body, so it won't be influenced by gravity or other forces
|
||||
atari = game.add.physicsSprite(300, 450, 'atari', null, Phaser.Types.BODY_STATIC);
|
||||
|
||||
// atari = 220px width (110 = center x)
|
||||
// ball = 32px width (16 = center x)
|
||||
|
||||
// Ball will be a dynamic body and fall based on gravity
|
||||
ball = game.add.physicsSprite(300-20, 0, 'ball');
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
Phaser.DebugUtils.renderPhysicsBodyInfo(atari.body, 32, 32);
|
||||
Phaser.DebugUtils.renderPhysicsBodyInfo(ball.body, 320, 32);
|
||||
|
||||
Phaser.DebugUtils.renderPhysicsBody(atari.body);
|
||||
Phaser.DebugUtils.renderPhysicsBody(ball.body);
|
||||
|
||||
}
|
||||
|
||||
})();
|
|
@ -77,8 +77,8 @@
|
|||
}
|
||||
}
|
||||
function render() {
|
||||
ship.body.renderDebugInfo(32, 32);
|
||||
}
|
||||
//ship.body.renderDebugInfo(32, 32);
|
||||
}
|
||||
function recycleBullet(bullet) {
|
||||
if(bullet.exists && bullet.x < -40 || bullet.x > 840 || bullet.y < -40 || bullet.y > 640) {
|
||||
bullet.exists = false;
|
||||
|
|
|
@ -122,7 +122,7 @@
|
|||
|
||||
function render() {
|
||||
|
||||
ship.body.renderDebugInfo(32, 32);
|
||||
//ship.body.renderDebugInfo(32, 32);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -9,10 +9,7 @@
|
|||
function create() {
|
||||
// This will create a Sprite positioned at the top-left of the game (0,0)
|
||||
// Try changing the 0, 0 values
|
||||
game.add.sprite(200, 100, 'bunny');
|
||||
game.add.sprite(0, 0, 'bunny');
|
||||
game.camera.texture.alpha = 0.5;
|
||||
//game.world.group.texture.flippedX = true;
|
||||
//game.world.group.transform.origin.setTo(game.stage.centerX, game.stage.centerY);
|
||||
//game.world.group.transform.skew.x = 1.2;
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
|
|
@ -16,12 +16,9 @@
|
|||
|
||||
// This will create a Sprite positioned at the top-left of the game (0,0)
|
||||
// Try changing the 0, 0 values
|
||||
game.add.sprite(200, 100, 'bunny');
|
||||
game.add.sprite(0, 0, 'bunny');
|
||||
|
||||
game.camera.texture.alpha = 0.5;
|
||||
//game.world.group.texture.flippedX = true;
|
||||
//game.world.group.transform.origin.setTo(game.stage.centerX, game.stage.centerY);
|
||||
//game.world.group.transform.skew.x = 1.2;
|
||||
|
||||
}
|
||||
|
||||
|
|
1922
build/phaser.d.ts
vendored
1922
build/phaser.d.ts
vendored
File diff suppressed because it is too large
Load diff
8680
build/phaser.js
8680
build/phaser.js
File diff suppressed because it is too large
Load diff
Loading…
Add table
Reference in a new issue