mirror of
https://github.com/photonstorm/phaser
synced 2024-11-10 15:14:47 +00:00
Merged Advanced Physics with core.
This commit is contained in:
parent
0591c7f2bd
commit
d19ad4976d
51 changed files with 7930 additions and 14968 deletions
|
@ -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;
|
||||
|
||||
|
|
|
@ -183,7 +183,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;
|
||||
|
|
|
@ -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,24 @@ 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 [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, shapeType?:number = 0): Sprite {
|
||||
return <Sprite> this._world.group.add(new Sprite(this._game, x, y, key, frame, Phaser.Types.BODY_DYNAMIC, 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)
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,52 +1,93 @@
|
|||
/// <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
|
||||
*/
|
||||
|
@ -57,6 +98,16 @@ module Phaser.Physics {
|
|||
*/
|
||||
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.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) {
|
||||
|
||||
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)
|
||||
{
|
||||
return this.bounds.width + this.deltaX;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.bounds.width - this.deltaX;
|
||||
}
|
||||
this.position.add(Phaser.Vec2Utils.scale(this.velocity, dt, this._tempVec2));
|
||||
|
||||
}
|
||||
this.angle += this.angularVelocity * dt;
|
||||
|
||||
public get hullHeight(): number {
|
||||
if (this.sprite)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
if (this.deltaY > 0)
|
||||
{
|
||||
return this.bounds.height + this.deltaY;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.bounds.height - this.deltaY;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
public resetForce() {
|
||||
this.force.setTo(0, 0);
|
||||
this.torque = 0;
|
||||
}
|
||||
|
||||
public get hullX(): number {
|
||||
public applyForce(force:Phaser.Vec2, p:Phaser.Vec2) {
|
||||
|
||||
if (this.position.x < this.oldPosition.x)
|
||||
{
|
||||
return this.position.x;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.oldPosition.x;
|
||||
}
|
||||
if (this.isDynamic == false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
if (this.isAwake == false)
|
||||
{
|
||||
this.awake(true);
|
||||
}
|
||||
|
||||
public get hullY(): number {
|
||||
this.force.add(force);
|
||||
|
||||
if (this.position.y < this.oldPosition.y)
|
||||
{
|
||||
return this.position.y;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.oldPosition.y;
|
||||
}
|
||||
Phaser.Vec2Utils.subtract(p, this.position, this._tempVec2);
|
||||
|
||||
}
|
||||
this.torque += Phaser.Vec2Utils.cross(this._tempVec2, force);
|
||||
|
||||
public get deltaXAbs(): number {
|
||||
return (this.deltaX > 0 ? this.deltaX : -this.deltaX);
|
||||
}
|
||||
}
|
||||
|
||||
public get deltaYAbs(): number {
|
||||
return (this.deltaY > 0 ? this.deltaY : -this.deltaY);
|
||||
}
|
||||
public applyForceToCenter(force:Phaser.Vec2) {
|
||||
|
||||
public get deltaX(): number {
|
||||
return this.position.x - this.oldPosition.x;
|
||||
}
|
||||
if (this.isDynamic == false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public get deltaY(): number {
|
||||
return this.position.y - this.oldPosition.y;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
// MOVE THESE TO A UTIL
|
||||
if (this.isAwake == false)
|
||||
{
|
||||
this.awake(true);
|
||||
}
|
||||
|
||||
public render(context:CanvasRenderingContext2D) {
|
||||
this.velocity.multiplyAddByScalar(impulse, this.massInverted);
|
||||
|
||||
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();
|
||||
Phaser.Vec2Utils.subtract(p, this.position, this._tempVec2);
|
||||
|
||||
// center point
|
||||
context.fillStyle = 'rgb(0,255,0)';
|
||||
context.fillRect(this.position.x, this.position.y, 2, 2);
|
||||
this.angularVelocity += Phaser.Vec2Utils.cross(this._tempVec2, impulse) * this.inertiaInverted;
|
||||
|
||||
if (this.touching & Phaser.Types.LEFT)
|
||||
{
|
||||
context.beginPath();
|
||||
context.strokeStyle = 'rgb(255,0,0)';
|
||||
context.moveTo(this.position.x - this.bounds.halfWidth, this.position.y - this.bounds.halfHeight);
|
||||
context.lineTo(this.position.x - this.bounds.halfWidth, this.position.y + this.bounds.halfHeight);
|
||||
context.stroke();
|
||||
context.closePath();
|
||||
}
|
||||
if (this.touching & Phaser.Types.RIGHT)
|
||||
{
|
||||
context.beginPath();
|
||||
context.strokeStyle = 'rgb(255,0,0)';
|
||||
context.moveTo(this.position.x + this.bounds.halfWidth, this.position.y - this.bounds.halfHeight);
|
||||
context.lineTo(this.position.x + this.bounds.halfWidth, this.position.y + this.bounds.halfHeight);
|
||||
context.stroke();
|
||||
context.closePath();
|
||||
}
|
||||
}
|
||||
|
||||
if (this.touching & Phaser.Types.UP)
|
||||
{
|
||||
context.beginPath();
|
||||
context.strokeStyle = 'rgb(255,0,0)';
|
||||
context.moveTo(this.position.x - this.bounds.halfWidth, this.position.y - this.bounds.halfHeight);
|
||||
context.lineTo(this.position.x + this.bounds.halfWidth, this.position.y - this.bounds.halfHeight);
|
||||
context.stroke();
|
||||
context.closePath();
|
||||
}
|
||||
if (this.touching & Phaser.Types.DOWN)
|
||||
{
|
||||
context.beginPath();
|
||||
context.strokeStyle = 'rgb(255,0,0)';
|
||||
context.moveTo(this.position.x - this.bounds.halfWidth, this.position.y + this.bounds.halfHeight);
|
||||
context.lineTo(this.position.x + this.bounds.halfWidth, this.position.y + this.bounds.halfHeight);
|
||||
context.stroke();
|
||||
context.closePath();
|
||||
}
|
||||
public applyAngularImpulse(impulse: number) {
|
||||
|
||||
}
|
||||
if (this.isDynamic == false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.isAwake == false)
|
||||
{
|
||||
this.awake(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render debug infos. (including name, bounds info, position and some other properties)
|
||||
* @param x {number} X position of the debug info to be rendered.
|
||||
* @param y {number} Y position of the debug info to be rendered.
|
||||
* @param [color] {number} color of the debug info to be rendered. (format is css color string)
|
||||
*/
|
||||
public renderDebugInfo(x: number, y: number, color?: string = 'rgb(255,255,255)') {
|
||||
this.angularVelocity += impulse * this.inertiaInverted;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
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="../../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,12 +33,12 @@ module Phaser.Physics.Advanced {
|
|||
public static debug: HTMLTextAreaElement;
|
||||
|
||||
public static clear() {
|
||||
Manager.debug.textContent = "";
|
||||
//Manager.debug.textContent = "";
|
||||
Manager.log = [];
|
||||
}
|
||||
|
||||
public static write(s: string) {
|
||||
Manager.debug.textContent += s + "\n";
|
||||
//Manager.debug.textContent += s + "\n";
|
||||
}
|
||||
|
||||
public static writeAll() {
|
||||
|
@ -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;
|
||||
|
@ -119,19 +123,21 @@ module Phaser.Physics.Advanced {
|
|||
public lastTime: number = Date.now();
|
||||
public frameRateHz: number = 60;
|
||||
public timeDelta: number = 0;
|
||||
//public paused: bool = false;
|
||||
//public step: bool = false; // step through the simulation (i.e. per click)
|
||||
public paused: bool = true;
|
||||
public paused: bool = false;
|
||||
public step: bool = false; // step through the simulation (i.e. per click)
|
||||
//public paused: bool = true;
|
||||
//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;
|
||||
|
@ -176,6 +182,22 @@ module Phaser.Physics.Advanced {
|
|||
|
||||
}
|
||||
|
||||
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,11 +14,13 @@
|
|||
* 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._manager = manager;
|
||||
|
||||
this.bodies = [];
|
||||
this.bodyHash = {};
|
||||
|
@ -29,7 +31,7 @@ module Phaser.Physics.Advanced {
|
|||
this.numContacts = 0;
|
||||
this.contactSolvers = [];
|
||||
|
||||
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;
|
||||
|
@ -37,6 +39,8 @@ module Phaser.Physics.Advanced {
|
|||
|
||||
}
|
||||
|
||||
private _manager: Phaser.Physics.Manager;
|
||||
|
||||
// Delta Timer
|
||||
private _delta: number;
|
||||
private _deltaInv: number;
|
||||
|
@ -68,7 +72,7 @@ module Phaser.Physics.Advanced {
|
|||
|
||||
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 bodies: Body[];
|
||||
public joints: IJoint[];
|
|
@ -1,680 +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[] = [];
|
||||
|
||||
// Length of the shapes array
|
||||
public shapesLength: number;
|
||||
|
||||
// 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);
|
||||
|
||||
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.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) {
|
||||
|
||||
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:number) {
|
||||
|
||||
this.position.add(Phaser.Vec2Utils.scale(this.velocity, dt, this._tempVec2));
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
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,17 +10,17 @@
|
|||
* 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);
|
||||
x = Manager.pixelsToMeters(x);
|
||||
y = Manager.pixelsToMeters(y);
|
||||
width = Manager.pixelsToMeters(width);
|
||||
height = Manager.pixelsToMeters(height);
|
||||
|
||||
var hw = width * 0.5;
|
||||
var hh = height * 0.5;
|
|
@ -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 {
|
||||
|
||||
|
@ -34,9 +34,9 @@ module Phaser.Physics.Advanced {
|
|||
findVertexByPoint(p: Phaser.Vec2, minDist: number): number;
|
||||
|
||||
verts: Phaser.Vec2[];
|
||||
planes: Phaser.Physics.Advanced.Plane[];
|
||||
planes: Phaser.Physics.Plane[];
|
||||
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,14 @@ 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);
|
||||
|
||||
}
|
||||
|
||||
|
@ -43,29 +49,53 @@ 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.shapes.length; 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 + verts[0].x) * 50, (body.position.y + verts[0].y) * 50);
|
||||
|
||||
for (var i = 0; i < verts.length; i++) {
|
||||
DebugUtils.context.lineTo((body.position.x + verts[i].x) * 50, (body.position.y + verts[i].y) * 50);
|
||||
}
|
||||
|
||||
DebugUtils.context.lineTo((body.position.x + verts[verts.length - 1].x) * 50, (body.position.y + verts[verts.length - 1].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;
|
||||
|
|
12
README.md
12
README.md
|
@ -44,15 +44,17 @@ TODO:
|
|||
* 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
|
||||
|
||||
|
@ -71,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
|
||||
|
@ -83,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.
|
||||
|
|
|
@ -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);
|
||||
|
|
8360
Tests/phaser.js
8360
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
|
||||
|
|
25
Tests/physics/simple test 1.js
Normal file
25
Tests/physics/simple test 1.js
Normal file
|
@ -0,0 +1,25 @@
|
|||
/// <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;
|
||||
var ball;
|
||||
function create() {
|
||||
// Add some gravity to the world, otherwise nothing will actually happen
|
||||
game.physics.gravity.setTo(0, 10);
|
||||
//atari = game.add.physicsSprite(220/2, 450, 'atari');
|
||||
atari = game.add.physicsSprite(320, 450, 'atari');
|
||||
// We'll make the atari sprite a static body, so it won't be influenced by gravity or other forces
|
||||
atari.body.type = Phaser.Types.BODY_STATIC;
|
||||
ball = game.add.physicsSprite(330, 0, 'ball', null, 0);
|
||||
}
|
||||
function render() {
|
||||
Phaser.DebugUtils.renderPhysicsBody(atari.body);
|
||||
Phaser.DebugUtils.renderPhysicsBody(ball.body);
|
||||
}
|
||||
})();
|
40
Tests/physics/simple test 1.ts
Normal file
40
Tests/physics/simple test 1.ts
Normal file
|
@ -0,0 +1,40 @@
|
|||
/// <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, 10);
|
||||
|
||||
//atari = game.add.physicsSprite(220/2, 450, 'atari');
|
||||
atari = game.add.physicsSprite(320, 450, 'atari');
|
||||
// We'll make the atari sprite a static body, so it won't be influenced by gravity or other forces
|
||||
atari.body.type = Phaser.Types.BODY_STATIC;
|
||||
|
||||
ball = game.add.physicsSprite(330, 0, 'ball', null, 0);
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
|
|
1636
build/phaser.d.ts
vendored
1636
build/phaser.d.ts
vendored
File diff suppressed because it is too large
Load diff
8360
build/phaser.js
8360
build/phaser.js
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue