mirror of
https://github.com/wassname/phaser.git
synced 2026-06-27 16:10:15 +08:00
Preparing for 1.0 branch
This commit is contained in:
Binary file not shown.
@@ -186,6 +186,14 @@
|
||||
<Content Include="net\Net.js">
|
||||
<DependentUpon>Net.ts</DependentUpon>
|
||||
</Content>
|
||||
<TypeScriptCompile Include="physics\ArcadePhysics.ts" />
|
||||
<TypeScriptCompile Include="physics\AdvancedPhysics.ts" />
|
||||
<Content Include="physics\AdvancedPhysics.js">
|
||||
<DependentUpon>AdvancedPhysics.ts</DependentUpon>
|
||||
</Content>
|
||||
<Content Include="physics\ArcadePhysics.js">
|
||||
<DependentUpon>ArcadePhysics.ts</DependentUpon>
|
||||
</Content>
|
||||
<Content Include="physics\Body.js">
|
||||
<DependentUpon>Body.ts</DependentUpon>
|
||||
</Content>
|
||||
@@ -270,6 +278,10 @@
|
||||
<Content Include="system\screens\OrientationScreen.js">
|
||||
<DependentUpon>OrientationScreen.ts</DependentUpon>
|
||||
</Content>
|
||||
<TypeScriptCompile Include="utils\BodyUtils.ts" />
|
||||
<Content Include="utils\BodyUtils.js">
|
||||
<DependentUpon>BodyUtils.ts</DependentUpon>
|
||||
</Content>
|
||||
<Content Include="utils\CircleUtils.js">
|
||||
<DependentUpon>CircleUtils.ts</DependentUpon>
|
||||
</Content>
|
||||
|
||||
@@ -169,6 +169,12 @@ module Phaser {
|
||||
*/
|
||||
public scaleMode: number;
|
||||
|
||||
/**
|
||||
* If set to true the game will never pause when the browser or browser tab loses focuses
|
||||
* @type {boolean}
|
||||
*/
|
||||
public disableVisibilityChange: bool = false;
|
||||
|
||||
/**
|
||||
* Stage boot
|
||||
*/
|
||||
@@ -230,6 +236,11 @@ module Phaser {
|
||||
*/
|
||||
private visibilityChange(event) {
|
||||
|
||||
if (this.disableVisibilityChange)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.type == 'pagehide' || event.type == 'blur' || document['hidden'] == true || document['webkitHidden'] == true)
|
||||
{
|
||||
if (this._game.paused == false)
|
||||
|
||||
@@ -160,6 +160,13 @@ module Phaser.Components {
|
||||
*/
|
||||
public isDynamic: bool = false;
|
||||
|
||||
/**
|
||||
* The crop rectangle allows you to control which part of the sprite texture is rendered without distorting it.
|
||||
* Set to null to disable, set to a Phaser.Rectangle object to control the region that will be rendered, anything outside the rectangle is ignored.
|
||||
* @type {Phaser.Rectangle}
|
||||
*/
|
||||
public crop: Phaser.Rectangle;
|
||||
|
||||
/**
|
||||
* Updates the texture being used to render the Sprite.
|
||||
* Called automatically by SpriteUtils.loadTexture and SpriteUtils.loadDynamicTexture.
|
||||
|
||||
@@ -393,6 +393,7 @@ module Phaser.Components.Sprite {
|
||||
if (this.bringToTop)
|
||||
{
|
||||
this._parent.bringToTop();
|
||||
//this._parent.game.world.group.bringToTop(this._parent);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+11
-5
@@ -151,7 +151,7 @@ module Phaser {
|
||||
|
||||
/**
|
||||
* Override this function to handle any deleting or "shutdown" type operations you might need,
|
||||
* such as removing traditional Flash children like Basic objects.
|
||||
* such as removing traditional children like Basic objects.
|
||||
*/
|
||||
public destroy() {
|
||||
|
||||
@@ -417,10 +417,10 @@ module Phaser {
|
||||
* @param y {number} Y position of the new sprite.
|
||||
* @param [key] {string} The image key as defined in the Game.Cache to use as the texture for this sprite
|
||||
* @param [frame] {string|number} If the sprite uses an image from a texture atlas or sprite sheet you can pass the frame here. Either a number for a frame ID or a string for a frame name.
|
||||
* @param [bodyType] {number} The physics body type of the object (defaults to BODY_DYNAMIC)
|
||||
* @param [bodyType] {number} The physics body type of the object (defaults to BODY_DISABLED)
|
||||
* @returns {Sprite} The newly created sprite object.
|
||||
*/
|
||||
public addNewSprite(x: number, y: number, key?: string = '', frame? = null, bodyType?: number = Phaser.Types.BODY_DYNAMIC): Sprite {
|
||||
public addNewSprite(x: number, y: number, key?: string = '', frame? = null, bodyType?: number = Phaser.Types.BODY_DISABLED): Sprite {
|
||||
return <Sprite> this.add(new Sprite(this.game, x, y, key, frame, bodyType));
|
||||
}
|
||||
|
||||
@@ -527,7 +527,7 @@ module Phaser {
|
||||
*/
|
||||
public remove(object, splice: bool = false) {
|
||||
|
||||
console.log('removing from group');
|
||||
//console.log('removing from group: ', object.name);
|
||||
|
||||
this._i = this.members.indexOf(object);
|
||||
|
||||
@@ -546,7 +546,7 @@ module Phaser {
|
||||
this.members[this._i] = null;
|
||||
}
|
||||
|
||||
console.log('nulled');
|
||||
//console.log('nulled');
|
||||
|
||||
if (object['events'])
|
||||
{
|
||||
@@ -728,6 +728,12 @@ module Phaser {
|
||||
*/
|
||||
public sortHandler(obj1, obj2): number {
|
||||
|
||||
if (!obj1 || !obj2)
|
||||
{
|
||||
//console.log('null objects in sort', obj1, obj2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (obj1[this._sortIndex] < obj2[this._sortIndex])
|
||||
{
|
||||
return this._sortOrder;
|
||||
|
||||
@@ -71,9 +71,9 @@ module Phaser {
|
||||
|
||||
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.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);
|
||||
@@ -88,6 +88,7 @@ module Phaser {
|
||||
this.scale = this.transform.scale;
|
||||
this.alpha = this.texture.alpha;
|
||||
this.origin = this.transform.origin;
|
||||
this.crop = this.texture.crop;
|
||||
|
||||
}
|
||||
|
||||
@@ -255,6 +256,13 @@ module Phaser {
|
||||
*/
|
||||
public scale: Phaser.Vec2;
|
||||
|
||||
/**
|
||||
* The crop rectangle allows you to control which part of the sprite texture is rendered without distorting it.
|
||||
* Set to null to disable, set to a Phaser.Rectangle object to control the region that will be rendered, anything outside the rectangle is ignored.
|
||||
* @type {Phaser.Rectangle}
|
||||
*/
|
||||
public crop: Phaser.Rectangle;
|
||||
|
||||
/**
|
||||
* The origin of the Sprite around which rotation and positioning takes place.
|
||||
* This is a reference to Sprite.transform.origin
|
||||
|
||||
@@ -0,0 +1,386 @@
|
||||
/// <reference path="../Game.ts" />
|
||||
/// <reference path="Body.ts" />
|
||||
/// <reference path="joints/Joint.ts" />
|
||||
/// <reference path="Space.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - Physics Manager
|
||||
*
|
||||
* The Physics Manager is responsible for looking after, creating and colliding
|
||||
* all of the physics bodies and joints in the world.
|
||||
*/
|
||||
|
||||
module Phaser.Physics {
|
||||
|
||||
export class AdvancedPhysics {
|
||||
|
||||
constructor(game: Game) {
|
||||
|
||||
this.game = game;
|
||||
|
||||
this.gravity = new Phaser.Vec2;
|
||||
|
||||
this.space = new Space(this);
|
||||
|
||||
this.collision = new Collision();
|
||||
|
||||
}
|
||||
|
||||
public collision;
|
||||
|
||||
/**
|
||||
* Local reference to Game.
|
||||
*/
|
||||
public game: Game;
|
||||
|
||||
public static debug: HTMLTextAreaElement;
|
||||
|
||||
public static clear() {
|
||||
//Manager.debug.textContent = "";
|
||||
Manager.log = [];
|
||||
}
|
||||
|
||||
public static write(s: string) {
|
||||
//Manager.debug.textContent += s + "\n";
|
||||
}
|
||||
|
||||
public static writeAll() {
|
||||
|
||||
for (var i = 0; i < Manager.log.length; i++)
|
||||
{
|
||||
//Manager.debug.textContent += Manager.log[i];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static log = [];
|
||||
|
||||
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";
|
||||
s += "Angle: " + body.angle + "\n";
|
||||
s += "Force: " + body.force.toString() + "\n";
|
||||
s += "Torque: " + body.torque + "\n";
|
||||
s += "Bounds: " + body.bounds.toString() + "\n";
|
||||
s += "Shape ***\n";
|
||||
s += "Vert 0: " + body.shapes[0].verts[0].toString() + "\n";
|
||||
s += "Vert 1: " + body.shapes[0].verts[1].toString() + "\n";
|
||||
s += "Vert 2: " + body.shapes[0].verts[2].toString() + "\n";
|
||||
s += "Vert 3: " + body.shapes[0].verts[3].toString() + "\n";
|
||||
s += "TVert 0: " + body.shapes[0].tverts[0].toString() + "\n";
|
||||
s += "TVert 1: " + body.shapes[0].tverts[1].toString() + "\n";
|
||||
s += "TVert 2: " + body.shapes[0].tverts[2].toString() + "\n";
|
||||
s += "TVert 3: " + body.shapes[0].tverts[3].toString() + "\n";
|
||||
s += "Plane 0: " + body.shapes[0].planes[0].normal.toString() + "\n";
|
||||
s += "Plane 1: " + body.shapes[0].planes[1].normal.toString() + "\n";
|
||||
s += "Plane 2: " + body.shapes[0].planes[2].normal.toString() + "\n";
|
||||
s += "Plane 3: " + body.shapes[0].planes[3].normal.toString() + "\n";
|
||||
s += "TPlane 0: " + body.shapes[0].tplanes[0].normal.toString() + "\n";
|
||||
s += "TPlane 1: " + body.shapes[0].tplanes[1].normal.toString() + "\n";
|
||||
s += "TPlane 2: " + body.shapes[0].tplanes[2].normal.toString() + "\n";
|
||||
s += "TPlane 3: " + body.shapes[0].tplanes[3].normal.toString() + "\n";
|
||||
|
||||
Manager.log.push(s);
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
public static collision: Collision;
|
||||
|
||||
public static SHAPE_TYPE_CIRCLE: number = 0;
|
||||
public static SHAPE_TYPE_SEGMENT: number = 1;
|
||||
public static SHAPE_TYPE_POLY: number = 2;
|
||||
public static SHAPE_NUM_TYPES: number = 3;
|
||||
|
||||
public static JOINT_TYPE_ANGLE: number = 0;
|
||||
public static JOINT_TYPE_REVOLUTE: number = 1;
|
||||
public static JOINT_TYPE_WELD: number = 2;
|
||||
public static JOINT_TYPE_WHEEL: number = 3;
|
||||
public static JOINT_TYPE_PRISMATIC: number = 4;
|
||||
public static JOINT_TYPE_DISTANCE: number = 5;
|
||||
public static JOINT_TYPE_ROPE: number = 6;
|
||||
public static JOINT_TYPE_MOUSE: number = 7;
|
||||
|
||||
public static JOINT_LINEAR_SLOP: number = 0.0008;
|
||||
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 * 0.017453292519943294444444444444444;
|
||||
|
||||
public static JOINT_LIMIT_STATE_INACTIVE: number = 0;
|
||||
public static JOINT_LIMIT_STATE_AT_LOWER: number = 1;
|
||||
public static JOINT_LIMIT_STATE_AT_UPPER: number = 2;
|
||||
public static JOINT_LIMIT_STATE_EQUAL_LIMITS: number = 3;
|
||||
|
||||
public static CONTACT_SOLVER_COLLISION_SLOP: number = 0.0008;
|
||||
public static CONTACT_SOLVER_BAUMGARTE: number = 0.28;
|
||||
public static CONTACT_SOLVER_MAX_LINEAR_CORRECTION: number = 1;//Infinity;
|
||||
|
||||
public static bodyCounter: number = 0;
|
||||
public static jointCounter: number = 0;
|
||||
public static shapeCounter: number = 0;
|
||||
|
||||
public space: Space;
|
||||
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 step: bool = false; // step through the simulation (i.e. per click)
|
||||
public velocityIterations: number = 8;
|
||||
public positionIterations: number = 4;
|
||||
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;
|
||||
|
||||
// if rAf - why?
|
||||
frameTime = Math.floor(frameTime * 60 + 0.5) / 60;
|
||||
|
||||
//if (!mouseDown)
|
||||
//{
|
||||
// var p = canvasToWorld(mousePosition);
|
||||
// var body = space.findBodyByPoint(p);
|
||||
// //domCanvas.style.cursor = body ? "pointer" : "default";
|
||||
//}
|
||||
|
||||
if (!this.paused || this.step)
|
||||
{
|
||||
Manager.clear();
|
||||
|
||||
var h = 1 / this.frameRateHz;
|
||||
|
||||
this.timeDelta += frameTime;
|
||||
|
||||
if (this.step)
|
||||
{
|
||||
this.step = false;
|
||||
this.timeDelta = h;
|
||||
}
|
||||
|
||||
for (var maxSteps = 4; maxSteps > 0 && this.timeDelta >= h; maxSteps--)
|
||||
{
|
||||
this.space.step(h, this.velocityIterations, this.positionIterations, this.warmStarting, this.allowSleep);
|
||||
this.timeDelta -= h;
|
||||
}
|
||||
|
||||
if (this.timeDelta > h)
|
||||
{
|
||||
this.timeDelta = 0;
|
||||
}
|
||||
}
|
||||
|
||||
//frameCount++;
|
||||
|
||||
}
|
||||
|
||||
public addBody(body: Body) {
|
||||
this.space.addBody(body);
|
||||
}
|
||||
|
||||
public removeBody(body: Body) {
|
||||
this.space.removeBody(body);
|
||||
}
|
||||
|
||||
public addJoint(joint: IJoint) {
|
||||
this.space.addJoint(joint);
|
||||
}
|
||||
|
||||
public removeJoint(joint: IJoint) {
|
||||
this.space.removeJoint(joint);
|
||||
}
|
||||
|
||||
public pixelsToMeters(value: number): number {
|
||||
return value * 0.02;
|
||||
}
|
||||
|
||||
public metersToPixels(value: number): number {
|
||||
return value * 50;
|
||||
}
|
||||
|
||||
public static pixelsToMeters(value: number): number {
|
||||
return value * 0.02;
|
||||
}
|
||||
|
||||
public static metersToPixels(value: number): number {
|
||||
return value * 50;
|
||||
}
|
||||
|
||||
public static p2m(value: number): number {
|
||||
return value * 0.02;
|
||||
}
|
||||
|
||||
public static m2p(value: number): number {
|
||||
return value * 50;
|
||||
}
|
||||
|
||||
public static areaForCircle(radius_outer: number, radius_inner: number): number {
|
||||
return Math.PI * (radius_outer * radius_outer - radius_inner * radius_inner);
|
||||
}
|
||||
|
||||
public static inertiaForCircle(mass: number, center: Phaser.Vec2, radius_outer: number, radius_inner: number): number {
|
||||
return mass * ((radius_outer * radius_outer + radius_inner * radius_inner) * 0.5 + center.lengthSq());
|
||||
}
|
||||
|
||||
public static areaForSegment(a: Phaser.Vec2, b: Phaser.Vec2, radius: number): number {
|
||||
return radius * (Math.PI * radius + 2 * Phaser.Vec2Utils.distance(a, b));
|
||||
}
|
||||
|
||||
public static centroidForSegment(a: Phaser.Vec2, b: Phaser.Vec2): Phaser.Vec2 {
|
||||
return Phaser.Vec2Utils.scale(Phaser.Vec2Utils.add(a, b), 0.5);
|
||||
}
|
||||
|
||||
public static inertiaForSegment(mass: number, a: Phaser.Vec2, b: Phaser.Vec2): number {
|
||||
|
||||
var distsq = Phaser.Vec2Utils.distanceSq(b, a);
|
||||
var offset: Phaser.Vec2 = Phaser.Vec2Utils.scale(Phaser.Vec2Utils.add(a, b), 0.5);
|
||||
|
||||
return mass * (distsq / 12 + offset.lengthSq());
|
||||
|
||||
}
|
||||
|
||||
public static areaForPoly(verts: Phaser.Vec2[]): number {
|
||||
|
||||
var area = 0;
|
||||
|
||||
for (var i = 0; i < verts.length; i++)
|
||||
{
|
||||
area += Phaser.Vec2Utils.cross(verts[i], verts[(i + 1) % verts.length]);
|
||||
}
|
||||
|
||||
return area / 2;
|
||||
}
|
||||
|
||||
public static centroidForPoly(verts: Phaser.Vec2[]): Phaser.Vec2 {
|
||||
|
||||
var area = 0;
|
||||
var vsum = new Phaser.Vec2;
|
||||
|
||||
for (var i = 0; i < verts.length; i++)
|
||||
{
|
||||
var v1 = verts[i];
|
||||
var v2 = verts[(i + 1) % verts.length];
|
||||
var cross = Phaser.Vec2Utils.cross(v1, v2);
|
||||
|
||||
area += cross;
|
||||
|
||||
// SO many vecs created here - unroll these bad boys
|
||||
vsum.add(Phaser.Vec2Utils.scale(Phaser.Vec2Utils.add(v1, v2), cross));
|
||||
}
|
||||
|
||||
return Phaser.Vec2Utils.scale(vsum, 1 / (3 * area));
|
||||
|
||||
}
|
||||
|
||||
public static inertiaForPoly(mass: number, verts: Phaser.Vec2[], offset: Phaser.Vec2): number {
|
||||
|
||||
var sum1 = 0;
|
||||
var sum2 = 0;
|
||||
|
||||
for (var i = 0; i < verts.length; i++)
|
||||
{
|
||||
var v1 = Phaser.Vec2Utils.add(verts[i], offset);
|
||||
var v2 = Phaser.Vec2Utils.add(verts[(i + 1) % verts.length], offset);
|
||||
|
||||
var a = Phaser.Vec2Utils.cross(v2, v1);
|
||||
var b = Phaser.Vec2Utils.dot(v1, v1) + Phaser.Vec2Utils.dot(v1, v2) + Phaser.Vec2Utils.dot(v2, v2);
|
||||
|
||||
sum1 += a * b;
|
||||
sum2 += a;
|
||||
}
|
||||
|
||||
return (mass * sum1) / (6 * sum2);
|
||||
|
||||
}
|
||||
|
||||
public static inertiaForBox(mass: number, w: number, h: number) {
|
||||
return mass * (w * w + h * h) / 12;
|
||||
}
|
||||
|
||||
// Create the convex hull using the Gift wrapping algorithm (http://en.wikipedia.org/wiki/Gift_wrapping_algorithm)
|
||||
public static createConvexHull(points) {
|
||||
|
||||
// Find the right most point on the hull
|
||||
var i0 = 0;
|
||||
var x0 = points[0].x;
|
||||
|
||||
for (var i = 1; i < points.length; i++)
|
||||
{
|
||||
var x = points[i].x;
|
||||
|
||||
if (x > x0 || (x == x0 && points[i].y < points[i0].y))
|
||||
{
|
||||
i0 = i;
|
||||
x0 = x;
|
||||
}
|
||||
}
|
||||
|
||||
var n = points.length;
|
||||
var hull = [];
|
||||
var m = 0;
|
||||
var ih = i0;
|
||||
|
||||
while (1)
|
||||
{
|
||||
hull[m] = ih;
|
||||
|
||||
var ie = 0;
|
||||
|
||||
for (var j = 1; j < n; j++)
|
||||
{
|
||||
if (ie == ih)
|
||||
{
|
||||
ie = j;
|
||||
continue;
|
||||
}
|
||||
|
||||
var r = Phaser.Vec2Utils.subtract(points[ie], points[hull[m]]);
|
||||
var v = Phaser.Vec2Utils.subtract(points[j], points[hull[m]]);
|
||||
var c = Phaser.Vec2Utils.cross(r, v);
|
||||
|
||||
if (c < 0)
|
||||
{
|
||||
ie = j;
|
||||
}
|
||||
|
||||
// Collinearity check
|
||||
if (c == 0 && v.lengthSq() > r.lengthSq())
|
||||
{
|
||||
ie = j;
|
||||
}
|
||||
}
|
||||
|
||||
m++;
|
||||
ih = ie;
|
||||
|
||||
if (ie == i0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Copy vertices
|
||||
var newPoints = [];
|
||||
|
||||
for (var i = 0; i < m; ++i)
|
||||
{
|
||||
newPoints.push(points[hull[i]]);
|
||||
}
|
||||
|
||||
return newPoints;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
+8
-78
@@ -3,7 +3,8 @@
|
||||
/// <reference path="../math/Vec2Utils.ts" />
|
||||
/// <reference path="../math/Transform.ts" />
|
||||
/// <reference path="../math/TransformUtils.ts" />
|
||||
/// <reference path="Manager.ts" />
|
||||
/// <reference path="../utils/BodyUtils.ts" />
|
||||
/// <reference path="AdvancedPhysics.ts" />
|
||||
/// <reference path="joints/Joint.ts" />
|
||||
/// <reference path="Bounds.ts" />
|
||||
/// <reference path="Space.ts" />
|
||||
@@ -26,7 +27,7 @@ module Phaser.Physics {
|
||||
|
||||
constructor(sprite: Phaser.Sprite, type: number, x?: number = 0, y?: number = 0, shapeType?: number = 0) {
|
||||
|
||||
this.id = Phaser.Physics.Manager.bodyCounter++;
|
||||
this.id = Phaser.Physics.AdvancedPhysics.bodyCounter++;
|
||||
this.name = 'body' + this.id;
|
||||
this.type = type;
|
||||
|
||||
@@ -34,12 +35,12 @@ module Phaser.Physics {
|
||||
{
|
||||
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.position = new Phaser.Vec2(Phaser.Physics.AdvancedPhysics.pixelsToMeters(sprite.x), Phaser.Physics.AdvancedPhysics.pixelsToMeters(sprite.y));
|
||||
this.angle = this.game.math.degreesToRadians(sprite.rotation);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.position = new Phaser.Vec2(Phaser.Physics.Manager.pixelsToMeters(x), Phaser.Physics.Manager.pixelsToMeters(y));
|
||||
this.position = new Phaser.Vec2(Phaser.Physics.AdvancedPhysics.pixelsToMeters(x), Phaser.Physics.AdvancedPhysics.pixelsToMeters(y));
|
||||
this.angle = 0;
|
||||
}
|
||||
|
||||
@@ -71,11 +72,11 @@ module Phaser.Physics {
|
||||
{
|
||||
if (shapeType == 0)
|
||||
{
|
||||
this.addBox(0, 0, this.sprite.width, this.sprite.height, 1, 1, 1);
|
||||
Phaser.BodyUtils.addBox(this, 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);
|
||||
Phaser.BodyUtils.addCircle(this, Math.max(this.sprite.width, this.sprite.height) / 2, 0, 0, 1, 1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,22 +194,6 @@ module Phaser.Physics {
|
||||
public stepCount: number = 0;
|
||||
public space: Space;
|
||||
|
||||
public duplicate() {
|
||||
|
||||
console.log('body duplicate called');
|
||||
|
||||
//var body = new Body(this.type, this.transform.t, this.rotation);
|
||||
|
||||
//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;
|
||||
@@ -243,61 +228,6 @@ module Phaser.Physics {
|
||||
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
@@ -344,7 +274,7 @@ module Phaser.Physics {
|
||||
|
||||
public setPosition(x: number, y: number) {
|
||||
|
||||
this._newPosition.setTo(this.game.physics.pixelsToMeters(x), this.game.physics.pixelsToMeters(y));
|
||||
this._newPosition.setTo(Phaser.Physics.AdvancedPhysics.pixelsToMeters(x), Phaser.Physics.AdvancedPhysics.pixelsToMeters(y));
|
||||
|
||||
this.setTransform(this._newPosition, this.angle);
|
||||
|
||||
|
||||
@@ -72,19 +72,19 @@ module Phaser.Physics {
|
||||
}
|
||||
|
||||
public get x(): number {
|
||||
return Phaser.Physics.Manager.metersToPixels(this.mins.x);
|
||||
return AdvancedPhysics.metersToPixels(this.mins.x);
|
||||
}
|
||||
|
||||
public get y(): number {
|
||||
return Phaser.Physics.Manager.metersToPixels(this.mins.y);
|
||||
return AdvancedPhysics.metersToPixels(this.mins.y);
|
||||
}
|
||||
|
||||
public get width(): number {
|
||||
return Phaser.Physics.Manager.metersToPixels(this.maxs.x - this.mins.x);
|
||||
return AdvancedPhysics.metersToPixels(this.maxs.x - this.mins.x);
|
||||
}
|
||||
|
||||
public get height(): number {
|
||||
return Phaser.Physics.Manager.metersToPixels(this.maxs.y - this.mins.y);
|
||||
return AdvancedPhysics.metersToPixels(this.maxs.y - this.mins.y);
|
||||
}
|
||||
|
||||
public get right(): number {
|
||||
|
||||
+13
-13
@@ -5,7 +5,7 @@
|
||||
/// <reference path="shapes/Circle.ts" />
|
||||
/// <reference path="shapes/Poly.ts" />
|
||||
/// <reference path="shapes/Segment.ts" />
|
||||
/// <reference path="Manager.ts" />
|
||||
/// <reference path="AdvancedPhysics.ts" />
|
||||
/// <reference path="Body.ts" />
|
||||
/// <reference path="Contact.ts" />
|
||||
|
||||
@@ -22,51 +22,51 @@ module Phaser.Physics {
|
||||
public collide(a, b, contacts: Contact[]) {
|
||||
|
||||
// Circle (a is the circle)
|
||||
if (a.type == Manager.SHAPE_TYPE_CIRCLE)
|
||||
if (a.type == AdvancedPhysics.SHAPE_TYPE_CIRCLE)
|
||||
{
|
||||
if (b.type == Manager.SHAPE_TYPE_CIRCLE)
|
||||
if (b.type == AdvancedPhysics.SHAPE_TYPE_CIRCLE)
|
||||
{
|
||||
return this.circle2Circle(a, b, contacts);
|
||||
}
|
||||
else if (b.type == Manager.SHAPE_TYPE_SEGMENT)
|
||||
else if (b.type == AdvancedPhysics.SHAPE_TYPE_SEGMENT)
|
||||
{
|
||||
return this.circle2Segment(a, b, contacts);
|
||||
}
|
||||
else if (b.type == Manager.SHAPE_TYPE_POLY)
|
||||
else if (b.type == AdvancedPhysics.SHAPE_TYPE_POLY)
|
||||
{
|
||||
return this.circle2Poly(a, b, contacts);
|
||||
}
|
||||
}
|
||||
|
||||
// Segment (a is the segment)
|
||||
if (a.type == Manager.SHAPE_TYPE_SEGMENT)
|
||||
if (a.type == AdvancedPhysics.SHAPE_TYPE_SEGMENT)
|
||||
{
|
||||
if (b.type == Manager.SHAPE_TYPE_CIRCLE)
|
||||
if (b.type == AdvancedPhysics.SHAPE_TYPE_CIRCLE)
|
||||
{
|
||||
return this.circle2Segment(b, a, contacts);
|
||||
}
|
||||
else if (b.type == Manager.SHAPE_TYPE_SEGMENT)
|
||||
else if (b.type == AdvancedPhysics.SHAPE_TYPE_SEGMENT)
|
||||
{
|
||||
return this.segment2Segment(a, b, contacts);
|
||||
}
|
||||
else if (b.type == Manager.SHAPE_TYPE_POLY)
|
||||
else if (b.type == AdvancedPhysics.SHAPE_TYPE_POLY)
|
||||
{
|
||||
return this.segment2Poly(a, b, contacts);
|
||||
}
|
||||
}
|
||||
|
||||
// Poly (a is the poly)
|
||||
if (a.type == Manager.SHAPE_TYPE_POLY)
|
||||
if (a.type == AdvancedPhysics.SHAPE_TYPE_POLY)
|
||||
{
|
||||
if (b.type == Manager.SHAPE_TYPE_CIRCLE)
|
||||
if (b.type == AdvancedPhysics.SHAPE_TYPE_CIRCLE)
|
||||
{
|
||||
return this.circle2Poly(b, a, contacts);
|
||||
}
|
||||
else if (b.type == Manager.SHAPE_TYPE_SEGMENT)
|
||||
else if (b.type == AdvancedPhysics.SHAPE_TYPE_SEGMENT)
|
||||
{
|
||||
return this.segment2Poly(b, a, contacts);
|
||||
}
|
||||
else if (b.type == Manager.SHAPE_TYPE_POLY)
|
||||
else if (b.type == AdvancedPhysics.SHAPE_TYPE_POLY)
|
||||
{
|
||||
return this.poly2Poly(a, b, contacts);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/// <reference path="../math/Vec2.ts" />
|
||||
/// <reference path="../math/Vec2Utils.ts" />
|
||||
/// <reference path="Manager.ts" />
|
||||
/// <reference path="AdvancedPhysics.ts" />
|
||||
/// <reference path="Body.ts" />
|
||||
/// <reference path="shapes/Shape.ts" />
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/// <reference path="../math/Vec2.ts" />
|
||||
/// <reference path="../geom/Point.ts" />
|
||||
/// <reference path="../math/Vec2Utils.ts" />
|
||||
/// <reference path="Manager.ts" />
|
||||
/// <reference path="AdvancedPhysics.ts" />
|
||||
/// <reference path="Body.ts" />
|
||||
/// <reference path="shapes/Shape.ts" />
|
||||
/// <reference path="Contact.ts" />
|
||||
@@ -190,22 +190,22 @@ module Phaser.Physics {
|
||||
var body1: Body = this.shape1.body;
|
||||
var body2: Body = this.shape2.body;
|
||||
|
||||
Manager.write('solveVelocityConstraints. Body1: ' + body1.name + ' Body2: ' + body2.name);
|
||||
Manager.write('Shape 1: ' + this.shape1.type + ' Shape 2: ' + this.shape2.type);
|
||||
AdvancedPhysics.write('solveVelocityConstraints. Body1: ' + body1.name + ' Body2: ' + body2.name);
|
||||
AdvancedPhysics.write('Shape 1: ' + this.shape1.type + ' Shape 2: ' + this.shape2.type);
|
||||
|
||||
var m1_inv = body1.massInverted;
|
||||
var i1_inv = body1.inertiaInverted;
|
||||
var m2_inv = body2.massInverted;
|
||||
var i2_inv = body2.inertiaInverted;
|
||||
|
||||
Manager.write('m1_inv: ' + m1_inv);
|
||||
Manager.write('i1_inv: ' + i1_inv);
|
||||
Manager.write('m2_inv: ' + m2_inv);
|
||||
Manager.write('i2_inv: ' + i2_inv);
|
||||
AdvancedPhysics.write('m1_inv: ' + m1_inv);
|
||||
AdvancedPhysics.write('i1_inv: ' + i1_inv);
|
||||
AdvancedPhysics.write('m2_inv: ' + m2_inv);
|
||||
AdvancedPhysics.write('i2_inv: ' + i2_inv);
|
||||
|
||||
for (var i = 0; i < this.contacts.length; i++)
|
||||
{
|
||||
Manager.write('------------ solve con ' + i);
|
||||
AdvancedPhysics.write('------------ solve con ' + i);
|
||||
|
||||
var con: Contact = this.contacts[i];
|
||||
var n: Phaser.Vec2 = con.normal;
|
||||
@@ -222,25 +222,25 @@ module Phaser.Physics {
|
||||
Phaser.Vec2Utils.multiplyAdd(body1.velocity, Phaser.Vec2Utils.perp(r1), body1.angularVelocity, v1);
|
||||
//var v1 = vec2.mad(body1.v, vec2.perp(r1), body1.w);
|
||||
|
||||
Manager.write('v1 ' + v1.toString());
|
||||
AdvancedPhysics.write('v1 ' + v1.toString());
|
||||
|
||||
Phaser.Vec2Utils.multiplyAdd(body2.velocity, Phaser.Vec2Utils.perp(r2), body2.angularVelocity, v2);
|
||||
//var v2 = vec2.mad(body2.v, vec2.perp(r2), body2.w);
|
||||
|
||||
Manager.write('v2 ' + v2.toString());
|
||||
AdvancedPhysics.write('v2 ' + v2.toString());
|
||||
|
||||
// Relative velocity at contact point
|
||||
var rv = new Phaser.Vec2;
|
||||
Phaser.Vec2Utils.subtract(v2, v1, rv);
|
||||
//var rv = vec2.sub(v2, v1);
|
||||
|
||||
Manager.write('rv ' + rv.toString());
|
||||
AdvancedPhysics.write('rv ' + rv.toString());
|
||||
|
||||
// Compute normal constraint impulse + adding bounce as a velocity bias
|
||||
// lambda_n = -EMn * J * V
|
||||
var lambda_n = -con.emn * (Phaser.Vec2Utils.dot(n, rv) + con.bounce);
|
||||
|
||||
Manager.write('lambda_n: ' + lambda_n);
|
||||
AdvancedPhysics.write('lambda_n: ' + lambda_n);
|
||||
|
||||
// Accumulate and clamp
|
||||
var lambda_n_old = con.lambdaNormal;
|
||||
@@ -248,7 +248,7 @@ module Phaser.Physics {
|
||||
//con.lambdaNormal = this.clamp(lambda_n_old + lambda_n, 0);
|
||||
lambda_n = con.lambdaNormal - lambda_n_old;
|
||||
|
||||
Manager.write('lambda_n clamped: ' + lambda_n);
|
||||
AdvancedPhysics.write('lambda_n clamped: ' + lambda_n);
|
||||
|
||||
// Compute frictional constraint impulse
|
||||
// lambda_t = -EMt * J * V
|
||||
@@ -266,7 +266,7 @@ module Phaser.Physics {
|
||||
//var impulse = vec2.rotate_vec(new vec2(lambda_n, lambda_t), n);
|
||||
var impulse = new Phaser.Vec2(lambda_n * n.x - lambda_t * n.y, lambda_t * n.x + lambda_n * n.y);
|
||||
|
||||
Manager.write('impulse: ' + impulse.toString());
|
||||
AdvancedPhysics.write('impulse: ' + impulse.toString());
|
||||
|
||||
body1.velocity.multiplyAddByScalar(impulse, -m1_inv);
|
||||
//body1.v.mad(impulse, -m1_inv);
|
||||
@@ -280,8 +280,8 @@ module Phaser.Physics {
|
||||
body2.angularVelocity += Phaser.Vec2Utils.cross(r2, impulse) * i2_inv;
|
||||
//body2.w += vec2.cross(r2, impulse) * i2_inv;
|
||||
|
||||
Manager.write('body1: ' + body1.toString());
|
||||
Manager.write('body2: ' + body2.toString());
|
||||
AdvancedPhysics.write('body1: ' + body1.toString());
|
||||
AdvancedPhysics.write('body2: ' + body2.toString());
|
||||
|
||||
}
|
||||
|
||||
@@ -292,7 +292,7 @@ module Phaser.Physics {
|
||||
var body1: Body = this.shape1.body;
|
||||
var body2: Body = this.shape2.body;
|
||||
|
||||
Manager.write('solvePositionConstraints');
|
||||
AdvancedPhysics.write('solvePositionConstraints');
|
||||
|
||||
var m1_inv = body1.massInverted;
|
||||
var i1_inv = body1.inertiaInverted;
|
||||
@@ -304,7 +304,7 @@ module Phaser.Physics {
|
||||
|
||||
for (var i = 0; i < this.contacts.length; i++)
|
||||
{
|
||||
Manager.write('------------- solvePositionConstraints ' + i);
|
||||
AdvancedPhysics.write('------------- solvePositionConstraints ' + i);
|
||||
|
||||
var con:Contact = this.contacts[i];
|
||||
var n:Phaser.Vec2 = con.normal;
|
||||
@@ -316,10 +316,10 @@ module Phaser.Physics {
|
||||
Phaser.Vec2Utils.rotate(con.r1_local, body1.angle, r1);
|
||||
Phaser.Vec2Utils.rotate(con.r2_local, body2.angle, r2);
|
||||
|
||||
Manager.write('r1_local.x = ' + con.r1_local.x + ' r1_local.y = ' + con.r1_local.y + ' angle: ' + body1.angle);
|
||||
Manager.write('r1 rotated: r1.x = ' + r1.x + ' r1.y = ' + r1.y);
|
||||
Manager.write('r2_local.x = ' + con.r2_local.x + ' r2_local.y = ' + con.r2_local.y + ' angle: ' + body2.angle);
|
||||
Manager.write('r2 rotated: r2.x = ' + r2.x + ' r2.y = ' + r2.y);
|
||||
AdvancedPhysics.write('r1_local.x = ' + con.r1_local.x + ' r1_local.y = ' + con.r1_local.y + ' angle: ' + body1.angle);
|
||||
AdvancedPhysics.write('r1 rotated: r1.x = ' + r1.x + ' r1.y = ' + r1.y);
|
||||
AdvancedPhysics.write('r2_local.x = ' + con.r2_local.x + ' r2_local.y = ' + con.r2_local.y + ' angle: ' + body2.angle);
|
||||
AdvancedPhysics.write('r2 rotated: r2.x = ' + r2.x + ' r2.y = ' + r2.y);
|
||||
|
||||
// Contact points (corrected)
|
||||
var p1 = new Phaser.Vec2;
|
||||
@@ -328,8 +328,8 @@ module Phaser.Physics {
|
||||
Phaser.Vec2Utils.add(body1.position, r1, p1);
|
||||
Phaser.Vec2Utils.add(body2.position, r2, p2);
|
||||
|
||||
Manager.write('body1.pos.x=' + body1.position.x + ' y=' + body1.position.y);
|
||||
Manager.write('body2.pos.x=' + body2.position.x + ' y=' + body2.position.y);
|
||||
AdvancedPhysics.write('body1.pos.x=' + body1.position.x + ' y=' + body1.position.y);
|
||||
AdvancedPhysics.write('body2.pos.x=' + body2.position.x + ' y=' + body2.position.y);
|
||||
|
||||
// Corrected delta vector
|
||||
var dp = new Phaser.Vec2;
|
||||
@@ -338,7 +338,7 @@ module Phaser.Physics {
|
||||
// Position constraint
|
||||
var c = Phaser.Vec2Utils.dot(dp, n) + con.depth;
|
||||
|
||||
var correction = this.clamp(Manager.CONTACT_SOLVER_BAUMGARTE * (c + Manager.CONTACT_SOLVER_COLLISION_SLOP), -Manager.CONTACT_SOLVER_MAX_LINEAR_CORRECTION, 0);
|
||||
var correction = this.clamp(AdvancedPhysics.CONTACT_SOLVER_BAUMGARTE * (c + AdvancedPhysics.CONTACT_SOLVER_COLLISION_SLOP), -AdvancedPhysics.CONTACT_SOLVER_MAX_LINEAR_CORRECTION, 0);
|
||||
|
||||
if (correction == 0)
|
||||
{
|
||||
@@ -367,13 +367,13 @@ module Phaser.Physics {
|
||||
body2.position.multiplyAddByScalar(impulse_dt, m2_inv);
|
||||
body2.angle += sn2 * lambda_dt * i2_inv;
|
||||
|
||||
Manager.write('body1.pos.x=' + body1.position.x + ' y=' + body1.position.y);
|
||||
Manager.write('body2.pos.x=' + body2.position.x + ' y=' + body2.position.y);
|
||||
AdvancedPhysics.write('body1.pos.x=' + body1.position.x + ' y=' + body1.position.y);
|
||||
AdvancedPhysics.write('body2.pos.x=' + body2.position.x + ' y=' + body2.position.y);
|
||||
}
|
||||
|
||||
Manager.write('max_penetration: ' + max_penetration);
|
||||
AdvancedPhysics.write('max_penetration: ' + max_penetration);
|
||||
|
||||
return max_penetration <= Manager.CONTACT_SOLVER_COLLISION_SLOP * 3;
|
||||
return max_penetration <= AdvancedPhysics.CONTACT_SOLVER_COLLISION_SLOP * 3;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -14,15 +14,7 @@ module Phaser.Physics {
|
||||
export class Manager {
|
||||
|
||||
constructor(game: Game) {
|
||||
|
||||
this.game = game;
|
||||
|
||||
this.gravity = new Phaser.Vec2;
|
||||
|
||||
this.space = new Space(this);
|
||||
|
||||
Manager.collision = new Collision();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -85,297 +77,8 @@ module Phaser.Physics {
|
||||
|
||||
}
|
||||
|
||||
public static collision: Collision;
|
||||
|
||||
public static SHAPE_TYPE_CIRCLE: number = 0;
|
||||
public static SHAPE_TYPE_SEGMENT: number = 1;
|
||||
public static SHAPE_TYPE_POLY: number = 2;
|
||||
public static SHAPE_NUM_TYPES: number = 3;
|
||||
|
||||
public static JOINT_TYPE_ANGLE: number = 0;
|
||||
public static JOINT_TYPE_REVOLUTE: number = 1;
|
||||
public static JOINT_TYPE_WELD: number = 2;
|
||||
public static JOINT_TYPE_WHEEL: number = 3;
|
||||
public static JOINT_TYPE_PRISMATIC: number = 4;
|
||||
public static JOINT_TYPE_DISTANCE: number = 5;
|
||||
public static JOINT_TYPE_ROPE: number = 6;
|
||||
public static JOINT_TYPE_MOUSE: number = 7;
|
||||
|
||||
public static JOINT_LINEAR_SLOP: number = 0.0008;
|
||||
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 * 0.017453292519943294444444444444444;
|
||||
|
||||
public static JOINT_LIMIT_STATE_INACTIVE: number = 0;
|
||||
public static JOINT_LIMIT_STATE_AT_LOWER: number = 1;
|
||||
public static JOINT_LIMIT_STATE_AT_UPPER: number = 2;
|
||||
public static JOINT_LIMIT_STATE_EQUAL_LIMITS: number = 3;
|
||||
|
||||
public static CONTACT_SOLVER_COLLISION_SLOP: number = 0.0008;
|
||||
public static CONTACT_SOLVER_BAUMGARTE: number = 0.28;
|
||||
public static CONTACT_SOLVER_MAX_LINEAR_CORRECTION: number = 1;//Infinity;
|
||||
|
||||
public static bodyCounter: number = 0;
|
||||
public static jointCounter: number = 0;
|
||||
public static shapeCounter: number = 0;
|
||||
|
||||
public space: Space;
|
||||
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 step: bool = false; // step through the simulation (i.e. per click)
|
||||
public velocityIterations: number = 8;
|
||||
public positionIterations: number = 4;
|
||||
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;
|
||||
|
||||
// if rAf - why?
|
||||
frameTime = Math.floor(frameTime * 60 + 0.5) / 60;
|
||||
|
||||
//if (!mouseDown)
|
||||
//{
|
||||
// var p = canvasToWorld(mousePosition);
|
||||
// var body = space.findBodyByPoint(p);
|
||||
// //domCanvas.style.cursor = body ? "pointer" : "default";
|
||||
//}
|
||||
|
||||
if (!this.paused || this.step)
|
||||
{
|
||||
Manager.clear();
|
||||
|
||||
var h = 1 / this.frameRateHz;
|
||||
|
||||
this.timeDelta += frameTime;
|
||||
|
||||
if (this.step)
|
||||
{
|
||||
this.step = false;
|
||||
this.timeDelta = h;
|
||||
}
|
||||
|
||||
for (var maxSteps = 4; maxSteps > 0 && this.timeDelta >= h; maxSteps--)
|
||||
{
|
||||
this.space.step(h, this.velocityIterations, this.positionIterations, this.warmStarting, this.allowSleep);
|
||||
this.timeDelta -= h;
|
||||
}
|
||||
|
||||
if (this.timeDelta > h)
|
||||
{
|
||||
this.timeDelta = 0;
|
||||
}
|
||||
}
|
||||
|
||||
//frameCount++;
|
||||
|
||||
}
|
||||
|
||||
public addBody(body: Body) {
|
||||
this.space.addBody(body);
|
||||
}
|
||||
|
||||
public removeBody(body: Body) {
|
||||
this.space.removeBody(body);
|
||||
}
|
||||
|
||||
public addJoint(joint: IJoint) {
|
||||
this.space.addJoint(joint);
|
||||
}
|
||||
|
||||
public removeJoint(joint: IJoint) {
|
||||
this.space.removeJoint(joint);
|
||||
}
|
||||
|
||||
public pixelsToMeters(value: number): number {
|
||||
return value * 0.02;
|
||||
}
|
||||
|
||||
public metersToPixels(value: number): number {
|
||||
return value * 50;
|
||||
}
|
||||
|
||||
public static pixelsToMeters(value: number): number {
|
||||
return value * 0.02;
|
||||
}
|
||||
|
||||
public static metersToPixels(value: number): number {
|
||||
return value * 50;
|
||||
}
|
||||
|
||||
public static p2m(value: number): number {
|
||||
return value * 0.02;
|
||||
}
|
||||
|
||||
public static m2p(value: number): number {
|
||||
return value * 50;
|
||||
}
|
||||
|
||||
public static areaForCircle(radius_outer: number, radius_inner: number): number {
|
||||
return Math.PI * (radius_outer * radius_outer - radius_inner * radius_inner);
|
||||
}
|
||||
|
||||
public static inertiaForCircle(mass: number, center: Phaser.Vec2, radius_outer: number, radius_inner: number): number {
|
||||
return mass * ((radius_outer * radius_outer + radius_inner * radius_inner) * 0.5 + center.lengthSq());
|
||||
}
|
||||
|
||||
public static areaForSegment(a: Phaser.Vec2, b: Phaser.Vec2, radius: number): number {
|
||||
return radius * (Math.PI * radius + 2 * Phaser.Vec2Utils.distance(a, b));
|
||||
}
|
||||
|
||||
public static centroidForSegment(a: Phaser.Vec2, b: Phaser.Vec2): Phaser.Vec2 {
|
||||
return Phaser.Vec2Utils.scale(Phaser.Vec2Utils.add(a, b), 0.5);
|
||||
}
|
||||
|
||||
public static inertiaForSegment(mass: number, a: Phaser.Vec2, b: Phaser.Vec2): number {
|
||||
|
||||
var distsq = Phaser.Vec2Utils.distanceSq(b, a);
|
||||
var offset: Phaser.Vec2 = Phaser.Vec2Utils.scale(Phaser.Vec2Utils.add(a, b), 0.5);
|
||||
|
||||
return mass * (distsq / 12 + offset.lengthSq());
|
||||
|
||||
}
|
||||
|
||||
public static areaForPoly(verts: Phaser.Vec2[]): number {
|
||||
|
||||
var area = 0;
|
||||
|
||||
for (var i = 0; i < verts.length; i++)
|
||||
{
|
||||
area += Phaser.Vec2Utils.cross(verts[i], verts[(i + 1) % verts.length]);
|
||||
}
|
||||
|
||||
return area / 2;
|
||||
}
|
||||
|
||||
public static centroidForPoly(verts: Phaser.Vec2[]): Phaser.Vec2 {
|
||||
|
||||
var area = 0;
|
||||
var vsum = new Phaser.Vec2;
|
||||
|
||||
for (var i = 0; i < verts.length; i++)
|
||||
{
|
||||
var v1 = verts[i];
|
||||
var v2 = verts[(i + 1) % verts.length];
|
||||
var cross = Phaser.Vec2Utils.cross(v1, v2);
|
||||
|
||||
area += cross;
|
||||
|
||||
// SO many vecs created here - unroll these bad boys
|
||||
vsum.add(Phaser.Vec2Utils.scale(Phaser.Vec2Utils.add(v1, v2), cross));
|
||||
}
|
||||
|
||||
return Phaser.Vec2Utils.scale(vsum, 1 / (3 * area));
|
||||
|
||||
}
|
||||
|
||||
public static inertiaForPoly(mass: number, verts: Phaser.Vec2[], offset: Phaser.Vec2): number {
|
||||
|
||||
var sum1 = 0;
|
||||
var sum2 = 0;
|
||||
|
||||
for (var i = 0; i < verts.length; i++)
|
||||
{
|
||||
var v1 = Phaser.Vec2Utils.add(verts[i], offset);
|
||||
var v2 = Phaser.Vec2Utils.add(verts[(i + 1) % verts.length], offset);
|
||||
|
||||
var a = Phaser.Vec2Utils.cross(v2, v1);
|
||||
var b = Phaser.Vec2Utils.dot(v1, v1) + Phaser.Vec2Utils.dot(v1, v2) + Phaser.Vec2Utils.dot(v2, v2);
|
||||
|
||||
sum1 += a * b;
|
||||
sum2 += a;
|
||||
}
|
||||
|
||||
return (mass * sum1) / (6 * sum2);
|
||||
|
||||
}
|
||||
|
||||
public static inertiaForBox(mass: number, w: number, h: number) {
|
||||
return mass * (w * w + h * h) / 12;
|
||||
}
|
||||
|
||||
// Create the convex hull using the Gift wrapping algorithm (http://en.wikipedia.org/wiki/Gift_wrapping_algorithm)
|
||||
public static createConvexHull(points) {
|
||||
|
||||
// Find the right most point on the hull
|
||||
var i0 = 0;
|
||||
var x0 = points[0].x;
|
||||
|
||||
for (var i = 1; i < points.length; i++)
|
||||
{
|
||||
var x = points[i].x;
|
||||
|
||||
if (x > x0 || (x == x0 && points[i].y < points[i0].y))
|
||||
{
|
||||
i0 = i;
|
||||
x0 = x;
|
||||
}
|
||||
}
|
||||
|
||||
var n = points.length;
|
||||
var hull = [];
|
||||
var m = 0;
|
||||
var ih = i0;
|
||||
|
||||
while (1)
|
||||
{
|
||||
hull[m] = ih;
|
||||
|
||||
var ie = 0;
|
||||
|
||||
for (var j = 1; j < n; j++)
|
||||
{
|
||||
if (ie == ih)
|
||||
{
|
||||
ie = j;
|
||||
continue;
|
||||
}
|
||||
|
||||
var r = Phaser.Vec2Utils.subtract(points[ie], points[hull[m]]);
|
||||
var v = Phaser.Vec2Utils.subtract(points[j], points[hull[m]]);
|
||||
var c = Phaser.Vec2Utils.cross(r, v);
|
||||
|
||||
if (c < 0)
|
||||
{
|
||||
ie = j;
|
||||
}
|
||||
|
||||
// Collinearity check
|
||||
if (c == 0 && v.lengthSq() > r.lengthSq())
|
||||
{
|
||||
ie = j;
|
||||
}
|
||||
}
|
||||
|
||||
m++;
|
||||
ih = ie;
|
||||
|
||||
if (ie == i0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Copy vertices
|
||||
var newPoints = [];
|
||||
|
||||
for (var i = 0; i < m; ++i)
|
||||
{
|
||||
newPoints.push(points[hull[i]]);
|
||||
}
|
||||
|
||||
return newPoints;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/// <reference path="../math/Vec2.ts" />
|
||||
/// <reference path="../math/Vec2Utils.ts" />
|
||||
/// <reference path="Manager.ts" />
|
||||
/// <reference path="AdvancedPhysics.ts" />
|
||||
/// <reference path="Body.ts" />
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/// <reference path="../math/Vec2.ts" />
|
||||
/// <reference path="../math/Vec2Utils.ts" />
|
||||
/// <reference path="Manager.ts" />
|
||||
/// <reference path="AdvancedPhysics.ts" />
|
||||
/// <reference path="Body.ts" />
|
||||
/// <reference path="shapes/Shape.ts" />
|
||||
/// <reference path="ContactSolver.ts" />
|
||||
@@ -18,7 +18,7 @@ module Phaser.Physics {
|
||||
|
||||
export class Space {
|
||||
|
||||
constructor(manager: Phaser.Physics.Manager) {
|
||||
constructor(manager: Phaser.Physics.AdvancedPhysics) {
|
||||
|
||||
this._manager = manager;
|
||||
|
||||
@@ -39,7 +39,7 @@ module Phaser.Physics {
|
||||
|
||||
}
|
||||
|
||||
private _manager: Phaser.Physics.Manager;
|
||||
private _manager: Phaser.Physics.AdvancedPhysics;
|
||||
|
||||
// Delta Timer
|
||||
private _delta: number;
|
||||
@@ -85,9 +85,9 @@ module Phaser.Physics {
|
||||
|
||||
public clear() {
|
||||
|
||||
Manager.shapeCounter = 0;
|
||||
Manager.bodyCounter = 0;
|
||||
Manager.jointCounter = 0;
|
||||
AdvancedPhysics.shapeCounter = 0;
|
||||
AdvancedPhysics.bodyCounter = 0;
|
||||
AdvancedPhysics.jointCounter = 0;
|
||||
|
||||
for (var i = 0; i < this.bodies.length; i++)
|
||||
{
|
||||
@@ -379,7 +379,7 @@ module Phaser.Physics {
|
||||
{
|
||||
var shape = body.shapes[j];
|
||||
|
||||
if (shape.type != Manager.SHAPE_TYPE_POLY)
|
||||
if (shape.type != AdvancedPhysics.SHAPE_TYPE_POLY)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -514,7 +514,7 @@ module Phaser.Physics {
|
||||
|
||||
var contactArr = [];
|
||||
|
||||
if (!Manager.collision.collide(this._shape1, this._shape2, contactArr))
|
||||
if (!AdvancedPhysics.collision.collide(this._shape1, this._shape2, contactArr))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/// <reference path="../../math/Vec2.ts" />
|
||||
/// <reference path="../../geom/Point.ts" />
|
||||
/// <reference path="../../math/Vec2Utils.ts" />
|
||||
/// <reference path="../Manager.ts" />
|
||||
/// <reference path="../AdvancedPhysics.ts" />
|
||||
/// <reference path="../Body.ts" />
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/// <reference path="../../math/Vec2.ts" />
|
||||
/// <reference path="../../geom/Point.ts" />
|
||||
/// <reference path="../../math/Vec2Utils.ts" />
|
||||
/// <reference path="../Manager.ts" />
|
||||
/// <reference path="../AdvancedPhysics.ts" />
|
||||
/// <reference path="../Body.ts" />
|
||||
|
||||
/**
|
||||
@@ -16,7 +16,7 @@ module Phaser.Physics {
|
||||
|
||||
constructor(type: number, body1:Phaser.Physics.Body, body2:Phaser.Physics.Body, collideConnected) {
|
||||
|
||||
this.id = Phaser.Physics.Manager.jointCounter++;
|
||||
this.id = AdvancedPhysics.jointCounter++;
|
||||
this.type = type;
|
||||
|
||||
this.body1 = body1;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/// <reference path="../../math/Vec2.ts" />
|
||||
/// <reference path="../Manager.ts" />
|
||||
/// <reference path="../AdvancedPhysics.ts" />
|
||||
/// <reference path="../Body.ts" />
|
||||
/// <reference path="Shape.ts" />
|
||||
/// <reference path="Poly.ts" />
|
||||
@@ -19,10 +19,10 @@ module Phaser.Physics.Shapes {
|
||||
|
||||
console.log('Box px', x, y, width, height);
|
||||
|
||||
x = Manager.pixelsToMeters(x);
|
||||
y = Manager.pixelsToMeters(y);
|
||||
width = Manager.pixelsToMeters(width);
|
||||
height = Manager.pixelsToMeters(height);
|
||||
x = Phaser.Physics.AdvancedPhysics.pixelsToMeters(x);
|
||||
y = Phaser.Physics.AdvancedPhysics.pixelsToMeters(y);
|
||||
width = Phaser.Physics.AdvancedPhysics.pixelsToMeters(width);
|
||||
height = Phaser.Physics.AdvancedPhysics.pixelsToMeters(height);
|
||||
|
||||
console.log('Box m', x, y, width, height);
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/// <reference path="../../math/Vec2.ts" />
|
||||
/// <reference path="../../math/Vec2Utils.ts" />
|
||||
/// <reference path="../Manager.ts" />
|
||||
/// <reference path="../AdvancedPhysics.ts" />
|
||||
/// <reference path="../Body.ts" />
|
||||
/// <reference path="Shape.ts" />
|
||||
|
||||
@@ -16,11 +16,11 @@ module Phaser.Physics.Shapes {
|
||||
|
||||
constructor(radius: number, x?: number = 0, y?: number = 0) {
|
||||
|
||||
super(Manager.SHAPE_TYPE_CIRCLE);
|
||||
super(AdvancedPhysics.SHAPE_TYPE_CIRCLE);
|
||||
|
||||
x = Manager.pixelsToMeters(x);
|
||||
y = Manager.pixelsToMeters(y);
|
||||
radius = Manager.pixelsToMeters(radius);
|
||||
x = AdvancedPhysics.pixelsToMeters(x);
|
||||
y = AdvancedPhysics.pixelsToMeters(y);
|
||||
radius = AdvancedPhysics.pixelsToMeters(radius);
|
||||
|
||||
this.center = new Phaser.Vec2(x, y);
|
||||
this.radius = radius;
|
||||
@@ -58,7 +58,7 @@ module Phaser.Physics.Shapes {
|
||||
}
|
||||
|
||||
public area(): number {
|
||||
return Manager.areaForCircle(this.radius, 0);
|
||||
return AdvancedPhysics.areaForCircle(this.radius, 0);
|
||||
}
|
||||
|
||||
public centroid(): Phaser.Vec2 {
|
||||
@@ -66,7 +66,7 @@ module Phaser.Physics.Shapes {
|
||||
}
|
||||
|
||||
public inertia(mass: number): number {
|
||||
return Manager.inertiaForCircle(mass, this.center, this.radius, 0);
|
||||
return AdvancedPhysics.inertiaForCircle(mass, this.center, this.radius, 0);
|
||||
}
|
||||
|
||||
public cacheData(xf: Transform) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/// <reference path="../../math/Vec2.ts" />
|
||||
/// <reference path="../../geom/Point.ts" />
|
||||
/// <reference path="../../math/Vec2Utils.ts" />
|
||||
/// <reference path="../Manager.ts" />
|
||||
/// <reference path="../AdvancedPhysics.ts" />
|
||||
/// <reference path="../Body.ts" />
|
||||
/// <reference path="Shape.ts" />
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/// <reference path="../../math/Vec2.ts" />
|
||||
/// <reference path="../../math/Vec2Utils.ts" />
|
||||
/// <reference path="../Manager.ts" />
|
||||
/// <reference path="../AdvancedPhysics.ts" />
|
||||
/// <reference path="../Body.ts" />
|
||||
/// <reference path="../Plane.ts" />
|
||||
/// <reference path="Shape.ts" />
|
||||
@@ -19,7 +19,7 @@ module Phaser.Physics.Shapes {
|
||||
// to seed this polygon (i.e. Vec2 objects, or just straight JS objects) and must wind COUNTER clockwise
|
||||
constructor(verts?) {
|
||||
|
||||
super(Manager.SHAPE_TYPE_POLY);
|
||||
super(AdvancedPhysics.SHAPE_TYPE_POLY);
|
||||
|
||||
this.verts = [];
|
||||
this.planes = [];
|
||||
@@ -117,15 +117,15 @@ module Phaser.Physics.Shapes {
|
||||
}
|
||||
|
||||
public area(): number {
|
||||
return Manager.areaForPoly(this.verts);
|
||||
return AdvancedPhysics.areaForPoly(this.verts);
|
||||
}
|
||||
|
||||
public centroid(): Phaser.Vec2 {
|
||||
return Manager.centroidForPoly(this.verts);
|
||||
return AdvancedPhysics.centroidForPoly(this.verts);
|
||||
}
|
||||
|
||||
public inertia(mass: number): number {
|
||||
return Manager.inertiaForPoly(mass, this.verts, new Phaser.Vec2);
|
||||
return AdvancedPhysics.inertiaForPoly(mass, this.verts, new Phaser.Vec2);
|
||||
}
|
||||
|
||||
public cacheData(xf:Transform) {
|
||||
@@ -134,7 +134,7 @@ module Phaser.Physics.Shapes {
|
||||
|
||||
var numVerts = this.verts.length;
|
||||
|
||||
Manager.write('----------- Poly cacheData = ' + numVerts);
|
||||
AdvancedPhysics.write('----------- Poly cacheData = ' + numVerts);
|
||||
|
||||
if (numVerts == 0)
|
||||
{
|
||||
@@ -145,7 +145,7 @@ module Phaser.Physics.Shapes {
|
||||
{
|
||||
this.tverts[i] = Phaser.TransformUtils.transform(xf, this.verts[i]);
|
||||
//this.tverts[i] = xf.transform(this.verts[i]);
|
||||
Manager.write('tvert' + i + ' = ' + this.tverts[i].toString());
|
||||
AdvancedPhysics.write('tvert' + i + ' = ' + this.tverts[i].toString());
|
||||
}
|
||||
|
||||
if (numVerts < 2)
|
||||
@@ -160,15 +160,15 @@ module Phaser.Physics.Shapes {
|
||||
var b = this.tverts[(i + 1) % numVerts];
|
||||
var n = Phaser.Vec2Utils.normalize(Phaser.Vec2Utils.perp(Phaser.Vec2Utils.subtract(a, b)));
|
||||
|
||||
Manager.write('a = ' + a.toString());
|
||||
Manager.write('b = ' + b.toString());
|
||||
Manager.write('n = ' + n.toString());
|
||||
AdvancedPhysics.write('a = ' + a.toString());
|
||||
AdvancedPhysics.write('b = ' + b.toString());
|
||||
AdvancedPhysics.write('n = ' + n.toString());
|
||||
|
||||
this.tplanes[i].normal = n;
|
||||
this.tplanes[i].d = Phaser.Vec2Utils.dot(n, a);
|
||||
|
||||
Manager.write('tplanes' + i + ' n = ' + this.tplanes[i].normal.toString());
|
||||
Manager.write('tplanes' + i + ' d = ' + this.tplanes[i].d.toString());
|
||||
AdvancedPhysics.write('tplanes' + i + ' n = ' + this.tplanes[i].normal.toString());
|
||||
AdvancedPhysics.write('tplanes' + i + ' d = ' + this.tplanes[i].d.toString());
|
||||
|
||||
this.bounds.addPoint(a);
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/// <reference path="../../math/Vec2.ts" />
|
||||
/// <reference path="../../math/Vec2Utils.ts" />
|
||||
/// <reference path="../Manager.ts" />
|
||||
/// <reference path="../AdvancedPhysics.ts" />
|
||||
/// <reference path="../Body.ts" />
|
||||
/// <reference path="Shape.ts" />
|
||||
|
||||
@@ -16,7 +16,7 @@ module Phaser.Physics.Shapes {
|
||||
|
||||
constructor(a, b, radius: number) {
|
||||
|
||||
super(Manager.SHAPE_TYPE_SEGMENT);
|
||||
super(AdvancedPhysics.SHAPE_TYPE_SEGMENT);
|
||||
|
||||
this.a = a.duplicate();
|
||||
this.b = b.duplicate();
|
||||
@@ -81,15 +81,15 @@ module Phaser.Physics.Shapes {
|
||||
}
|
||||
|
||||
public area(): number {
|
||||
return Manager.areaForSegment(this.a, this.b, this.radius);
|
||||
return AdvancedPhysics.areaForSegment(this.a, this.b, this.radius);
|
||||
}
|
||||
|
||||
public centroid(): Phaser.Vec2 {
|
||||
return Manager.centroidForSegment(this.a, this.b);
|
||||
return AdvancedPhysics.centroidForSegment(this.a, this.b);
|
||||
}
|
||||
|
||||
public inertia(mass: number): number {
|
||||
return Manager.inertiaForSegment(mass, this.a, this.b);
|
||||
return AdvancedPhysics.inertiaForSegment(mass, this.a, this.b);
|
||||
}
|
||||
|
||||
public cacheData(xf:Transform) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/// <reference path="../../math/Vec2.ts" />
|
||||
/// <reference path="../../math/Vec2Utils.ts" />
|
||||
/// <reference path="../Manager.ts" />
|
||||
/// <reference path="../AdvancedPhysics.ts" />
|
||||
/// <reference path="../Body.ts" />
|
||||
/// <reference path="../Bounds.ts" />
|
||||
/// <reference path="IShape.ts" />
|
||||
@@ -17,7 +17,7 @@ module Phaser.Physics {
|
||||
|
||||
constructor(type: number) {
|
||||
|
||||
this.id = Phaser.Physics.Manager.shapeCounter++;
|
||||
this.id = AdvancedPhysics.shapeCounter++;
|
||||
this.type = type;
|
||||
|
||||
this.elasticity = 0.0;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/// <reference path="../../math/Vec2.ts" />
|
||||
/// <reference path="../Manager.ts" />
|
||||
/// <reference path="../AdvancedPhysics.ts" />
|
||||
/// <reference path="../Body.ts" />
|
||||
/// <reference path="Shape.ts" />
|
||||
/// <reference path="Poly.ts" />
|
||||
@@ -16,12 +16,12 @@ module Phaser.Physics.Shapes {
|
||||
|
||||
constructor(x1: number, y1: number, x2: number, y2: number, x3: number, y3: number) {
|
||||
|
||||
x1 = Manager.pixelsToMeters(x1);
|
||||
y1 = Manager.pixelsToMeters(y1);
|
||||
x2 = Manager.pixelsToMeters(x2);
|
||||
y2 = Manager.pixelsToMeters(y2);
|
||||
x3 = Manager.pixelsToMeters(x3);
|
||||
y3 = Manager.pixelsToMeters(y3);
|
||||
x1 = Phaser.Physics.AdvancedPhysics.pixelsToMeters(x1);
|
||||
y1 = Phaser.Physics.AdvancedPhysics.pixelsToMeters(y1);
|
||||
x2 = Phaser.Physics.AdvancedPhysics.pixelsToMeters(x2);
|
||||
y2 = Phaser.Physics.AdvancedPhysics.pixelsToMeters(y2);
|
||||
x3 = Phaser.Physics.AdvancedPhysics.pixelsToMeters(x3);
|
||||
y3 = Phaser.Physics.AdvancedPhysics.pixelsToMeters(y3);
|
||||
|
||||
super([{ x: x1, y: y1 }, { x: x2, y: y2 }, { x: x3, y: y3 }]);
|
||||
|
||||
|
||||
@@ -459,6 +459,7 @@ module Phaser {
|
||||
}
|
||||
|
||||
sprite.renderOrderID = this._count;
|
||||
|
||||
this._count++;
|
||||
|
||||
// Reset our temp vars
|
||||
@@ -524,6 +525,18 @@ module Phaser {
|
||||
this._dy -= (this._dh * sprite.transform.origin.y);
|
||||
}
|
||||
|
||||
if (sprite.crop)
|
||||
{
|
||||
this._sx += sprite.crop.x * sprite.transform.scale.x;
|
||||
this._sy += sprite.crop.y * sprite.transform.scale.y;
|
||||
this._sw = sprite.crop.width * sprite.transform.scale.x;
|
||||
this._sh = sprite.crop.height * sprite.transform.scale.y;
|
||||
this._dx += sprite.crop.x * sprite.transform.scale.x;
|
||||
this._dy += sprite.crop.y * sprite.transform.scale.y;
|
||||
this._dw = sprite.crop.width * sprite.transform.scale.x;
|
||||
this._dh = sprite.crop.height * sprite.transform.scale.y;
|
||||
}
|
||||
|
||||
this._sx = Math.round(this._sx);
|
||||
this._sy = Math.round(this._sy);
|
||||
this._sw = Math.round(this._sw);
|
||||
|
||||
+11
-11
@@ -75,7 +75,7 @@ module Phaser {
|
||||
{
|
||||
this._sound = this.game.cache.getSoundData(this.key);
|
||||
this.totalDuration = this._sound.duration;
|
||||
console.log('sound has unlocked', this._sound);
|
||||
//console.log('sound has unlocked', this._sound);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -183,32 +183,32 @@ module Phaser {
|
||||
|
||||
if (this.currentTime >= this.duration)
|
||||
{
|
||||
console.log(this.currentMarker, 'has hit duration');
|
||||
//console.log(this.currentMarker, 'has hit duration');
|
||||
|
||||
if (this.usingWebAudio)
|
||||
{
|
||||
if (this.loop)
|
||||
{
|
||||
console.log('loop1');
|
||||
//console.log('loop1');
|
||||
|
||||
// won't work with markers, needs to reset the position
|
||||
this.onLoop.dispatch(this);
|
||||
|
||||
if (this.currentMarker == '')
|
||||
{
|
||||
console.log('loop2');
|
||||
//console.log('loop2');
|
||||
this.currentTime = 0;
|
||||
this.startTime = this.game.time.now;
|
||||
}
|
||||
else
|
||||
{
|
||||
console.log('loop3');
|
||||
//console.log('loop3');
|
||||
this.play(this.currentMarker, 0, this.volume, true, true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
console.log('stopping, no loop for marker');
|
||||
//console.log('stopping, no loop for marker');
|
||||
this.stop();
|
||||
}
|
||||
}
|
||||
@@ -241,7 +241,7 @@ module Phaser {
|
||||
*/
|
||||
public play(marker: string = '', position?: number = 0, volume?: number = 1, loop?: bool = false, forceRestart: bool = false) {
|
||||
|
||||
console.log('play', marker, 'current is', this.currentMarker);
|
||||
//console.log('play', marker, 'current is', this.currentMarker);
|
||||
|
||||
if (this.isPlaying == true && forceRestart == false && this.override == false)
|
||||
{
|
||||
@@ -251,7 +251,7 @@ module Phaser {
|
||||
|
||||
if (this.isPlaying && this.override)
|
||||
{
|
||||
console.log('asked to play', marker, 'but already playing', this.currentMarker);
|
||||
//console.log('asked to play', marker, 'but already playing', this.currentMarker);
|
||||
if (this.usingWebAudio)
|
||||
{
|
||||
if (typeof this._sound.stop === 'undefined')
|
||||
@@ -279,7 +279,7 @@ module Phaser {
|
||||
this.loop = this.markers[marker].loop;
|
||||
this.duration = this.markers[marker].duration * 1000;
|
||||
|
||||
console.log('marker info loaded', this.loop, this.duration);
|
||||
//console.log('marker info loaded', this.loop, this.duration);
|
||||
|
||||
this._tempMarker = marker;
|
||||
this._tempPosition = this.position;
|
||||
@@ -345,7 +345,7 @@ module Phaser {
|
||||
this.stopTime = this.startTime + this.duration;
|
||||
this.onPlay.dispatch(this);
|
||||
|
||||
console.log('playing, start', this.startTime, 'stop');
|
||||
//console.log('playing, start', this.startTime, 'stop');
|
||||
|
||||
}
|
||||
else
|
||||
@@ -459,7 +459,7 @@ module Phaser {
|
||||
*/
|
||||
public stop() {
|
||||
|
||||
console.log('Sound.stop', this.currentMarker);
|
||||
//console.log('Sound.stop', this.currentMarker);
|
||||
|
||||
if (this.isPlaying && this._sound)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
/// <reference path="../Game.ts" />
|
||||
/// <reference path="../geom/Point.ts" />
|
||||
/// <reference path="../geom/Rectangle.ts" />
|
||||
/// <reference path="../geom/Circle.ts" />
|
||||
/// <reference path="../physics/Body.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - BodyUtils
|
||||
*
|
||||
* A collection of methods useful for manipulating AdvancedPhysics Body objects.
|
||||
*/
|
||||
|
||||
module Phaser {
|
||||
|
||||
export class BodyUtils {
|
||||
|
||||
static duplicate(source: Phaser.Physics.Body, output?: Phaser.Physics.Body): Phaser.Physics.Body {
|
||||
|
||||
/*
|
||||
console.log('body duplicate called');
|
||||
|
||||
var newBody = new Phaser.Physics.Body(source.type, source.transform.t, source.rotation);
|
||||
|
||||
for (var i = 0; i < source.shapes.length; i++)
|
||||
{
|
||||
output.addShape(source.shapes[i].duplicate());
|
||||
}
|
||||
|
||||
output.resetMassData();
|
||||
*/
|
||||
|
||||
return output;
|
||||
|
||||
}
|
||||
|
||||
static addPoly(body: Phaser.Physics.Body, 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;
|
||||
|
||||
body.addShape(poly);
|
||||
body.resetMassData();
|
||||
|
||||
return poly;
|
||||
|
||||
}
|
||||
|
||||
static addTriangle(body: Phaser.Physics.Body, 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;
|
||||
|
||||
body.addShape(tri);
|
||||
body.resetMassData();
|
||||
|
||||
return tri;
|
||||
|
||||
}
|
||||
|
||||
static addBox(body: Phaser.Physics.Body, 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;
|
||||
|
||||
body.addShape(box);
|
||||
body.resetMassData();
|
||||
|
||||
return box;
|
||||
|
||||
}
|
||||
|
||||
static addCircle(body: Phaser.Physics.Body, 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;
|
||||
|
||||
body.addShape(circle);
|
||||
body.resetMassData();
|
||||
|
||||
return circle;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -124,7 +124,7 @@ module Phaser {
|
||||
{
|
||||
DebugUtils.context.beginPath();
|
||||
|
||||
if (body.shapes[s].type == Phaser.Physics.Manager.SHAPE_TYPE_POLY)
|
||||
if (body.shapes[s].type == Phaser.Physics.AdvancedPhysics.SHAPE_TYPE_POLY)
|
||||
{
|
||||
var verts = body.shapes[s].tverts;
|
||||
|
||||
@@ -140,7 +140,7 @@ module Phaser {
|
||||
// DebugUtils.context.lineTo(body.position.x * 50 + verts[0].x, body.position.y * 50 + verts[0].y);
|
||||
DebugUtils.context.lineTo(verts[0].x * 50, verts[0].y * 50);
|
||||
}
|
||||
else if (body.shapes[s].type == Phaser.Physics.Manager.SHAPE_TYPE_CIRCLE)
|
||||
else if (body.shapes[s].type == Phaser.Physics.AdvancedPhysics.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);
|
||||
|
||||
@@ -36,7 +36,6 @@ TODO:
|
||||
* If stage.clear set to false and game pauses, when it unpauses you still see the pause arrow - resolve this
|
||||
* Add clip support + shape options to Texture Component.
|
||||
* Make sure I'm using Point and not Vec2 when it's not a directional vector I need
|
||||
* Bug with setting scale or anything on a Sprite inside a Group, or maybe group.addNewSprite issue
|
||||
* Drag Sprite with "snap to center" uses local coords not world, so fails on scrolling world (no center lock works fine)
|
||||
* Need to be able to set the current tilemap layer, then the getTileXY default layer uses that one if no other given
|
||||
* Pointer worldX/Y don't appear to be correct for some reason
|
||||
@@ -62,8 +61,16 @@ TODO:
|
||||
* Stage lost to mute
|
||||
* When game is paused Pointer shouldn't process targetObjects / change cursor
|
||||
* Need to limit touch priority of items in groups?
|
||||
* Bring to Top doesn't seem to respect the group they are in
|
||||
* Add crop support
|
||||
* Check if it works from an iFrame
|
||||
* Bitmap Font support
|
||||
* Basic Window component (maybe a propogating Group?)
|
||||
* Put ArcadePhysics back in
|
||||
* Look at the N+ tile support maybe with ArcadePhysics?
|
||||
* Pixel-perfect click check
|
||||
* Check Flash atlas export is supported
|
||||
* Plug-in Support
|
||||
|
||||
|
||||
|
||||
V1.0.0
|
||||
|
||||
@@ -160,10 +167,10 @@ V1.0.0
|
||||
* Added Phaser.Net for browser and network specific functions, currently includes query string parsing and updating methods.
|
||||
* Added a new CSS3 Filters component. Apply blur, grayscale, sepia, brightness, contrast, hue rotation, invert, opacity and saturate filters to the games stage.
|
||||
* Fixed the CircleUtils.contains and containsPoint methods.
|
||||
* Fixed issue with Input.speed values being too high on touch events.
|
||||
|
||||
|
||||
|
||||
* Fixed issue with Input.speed values being too high on new touch events.
|
||||
* Added Sprite.bringToTop()
|
||||
* Added Stage.disableVisibilityChange to stop the auto pause/resume from ever firing.
|
||||
* Added crop support to the Texture component, so you can do Sprite.crop to restrict rendering to a specified Rectangle without distortion.
|
||||
|
||||
V0.9.6
|
||||
|
||||
|
||||
@@ -92,6 +92,10 @@
|
||||
<Content Include="cameras\world sprite.js">
|
||||
<DependentUpon>world sprite.ts</DependentUpon>
|
||||
</Content>
|
||||
<TypeScriptCompile Include="groups\bring to top 1.ts" />
|
||||
<Content Include="groups\bring to top 1.js">
|
||||
<DependentUpon>bring to top 1.ts</DependentUpon>
|
||||
</Content>
|
||||
<Content Include="groups\create group 1.js">
|
||||
<DependentUpon>create group 1.ts</DependentUpon>
|
||||
</Content>
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
(function () {
|
||||
var game = new Phaser.Game(this, 'game', 800, 600, init, create, update, render);
|
||||
function init() {
|
||||
game.load.image('beast', 'assets/pics/shadow_of_the_beast2_karamoon.png');
|
||||
game.load.image('snot', 'assets/pics/nslide_snot.png');
|
||||
game.load.image('atari1', 'assets/sprites/atari130xe.png');
|
||||
game.load.image('sonic', 'assets/sprites/sonic_havok_sanity.png');
|
||||
game.load.image('coke', 'assets/sprites/cokecan.png');
|
||||
game.load.image('disk', 'assets/sprites/oz_pov_melting_disk.png');
|
||||
game.load.start();
|
||||
}
|
||||
var group1;
|
||||
var group2;
|
||||
var coke;
|
||||
var disk;
|
||||
function create() {
|
||||
// Create a background image
|
||||
game.add.sprite(0, 0, 'beast');
|
||||
// Create a Group that will sit above the background image
|
||||
group1 = game.add.group(11);
|
||||
// Create a Group that will sit above Group 1
|
||||
group2 = game.add.group(11);
|
||||
// Now let's create some random sprites and enable them all for drag and 'bring to top'
|
||||
for(var i = 0; i < 10; i++) {
|
||||
//var tempSprite: Phaser.Sprite = group1.addNewSprite(game.stage.randomX, game.stage.randomY, 'atari1');
|
||||
//var tempSprite: Phaser.Sprite = new Phaser.Sprite(game, game.stage.randomX, game.stage.randomY, 'atari1');
|
||||
var tempSprite = game.add.sprite(game.stage.randomX, game.stage.randomY, 'atari1');
|
||||
tempSprite.name = 'atari' + i;
|
||||
tempSprite.input.start(i, false, true);
|
||||
tempSprite.input.enableDrag(false, true);
|
||||
group1.add(tempSprite);
|
||||
// Sonics
|
||||
//var tempSprite: Phaser.Sprite = group2.addNewSprite(game.stage.randomX, game.stage.randomY, 'sonic');
|
||||
//var tempSprite: Phaser.Sprite = new Phaser.Sprite(game, game.stage.randomX, game.stage.randomY, 'sonic');
|
||||
var tempSprite = game.add.sprite(game.stage.randomX, game.stage.randomY, 'sonic');
|
||||
tempSprite.name = 'sonic' + i;
|
||||
tempSprite.input.start(10 + i, false, true);
|
||||
tempSprite.input.enableDrag(false, true);
|
||||
group2.add(tempSprite);
|
||||
}
|
||||
// Add 2 control sprites into each group - these cannot be dragged but should be bought to the top each time
|
||||
coke = group1.addNewSprite(100, 100, 'coke');
|
||||
disk = group2.addNewSprite(400, 300, 'disk');
|
||||
// Create a foreground image - everything should appear behind this, even when dragged
|
||||
var snot = game.add.sprite(game.stage.centerX, game.stage.height, 'snot');
|
||||
snot.origin.setTo(0.5, 1);
|
||||
// You can click and drag any sprite but Sonic sprites should always appear above the Atari sprites
|
||||
// and both types of sprite should only ever appear above the background and behind the
|
||||
}
|
||||
function update() {
|
||||
if(game.input.keyboard.justReleased(Phaser.Keyboard.ONE)) {
|
||||
coke.bringToTop();
|
||||
}
|
||||
if(game.input.keyboard.justReleased(Phaser.Keyboard.TWO)) {
|
||||
disk.bringToTop();
|
||||
}
|
||||
}
|
||||
function render() {
|
||||
game.input.renderDebugInfo(32, 32);
|
||||
}
|
||||
})();
|
||||
+56
-14
@@ -3659,7 +3659,8 @@ var Phaser;
|
||||
this.startDrag(pointer);
|
||||
}
|
||||
if(this.bringToTop) {
|
||||
this._parent.group.bringToTop(this._parent);
|
||||
//this._parent.bringToTop();
|
||||
this._parent.game.world.group.bringToTop(this._parent);
|
||||
}
|
||||
}
|
||||
// Consume the event?
|
||||
@@ -3836,7 +3837,7 @@ var Phaser;
|
||||
}
|
||||
this.updateDrag(pointer);
|
||||
if(this.bringToTop) {
|
||||
this._parent.group.bringToTop(this._parent);
|
||||
this._parent.bringToTop();
|
||||
}
|
||||
this._parent.events.onDragStart.dispatch(this._parent, pointer);
|
||||
};
|
||||
@@ -7271,6 +7272,14 @@ var Phaser;
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Sprite.prototype.bringToTop = /**
|
||||
* Brings this Sprite to the top of its current Group, if set.
|
||||
*/
|
||||
function () {
|
||||
if(this.group) {
|
||||
this.group.bringToTop(this);
|
||||
}
|
||||
};
|
||||
Object.defineProperty(Sprite.prototype, "alpha", {
|
||||
get: /**
|
||||
* The alpha of the Sprite between 0 and 1, a value of 1 being fully opaque.
|
||||
@@ -8103,13 +8112,13 @@ var Phaser;
|
||||
* @param y {number} Y position of the new sprite.
|
||||
* @param [key] {string} The image key as defined in the Game.Cache to use as the texture for this sprite
|
||||
* @param [frame] {string|number} If the sprite uses an image from a texture atlas or sprite sheet you can pass the frame here. Either a number for a frame ID or a string for a frame name.
|
||||
* @param [bodyType] {number} The physics body type of the object (defaults to BODY_DYNAMIC)
|
||||
* @param [bodyType] {number} The physics body type of the object (defaults to BODY_DISABLED)
|
||||
* @returns {Sprite} The newly created sprite object.
|
||||
*/
|
||||
function (x, y, key, frame, bodyType) {
|
||||
if (typeof key === "undefined") { key = ''; }
|
||||
if (typeof frame === "undefined") { frame = null; }
|
||||
if (typeof bodyType === "undefined") { bodyType = Phaser.Types.BODY_DYNAMIC; }
|
||||
if (typeof bodyType === "undefined") { bodyType = Phaser.Types.BODY_DISABLED; }
|
||||
return this.add(new Phaser.Sprite(this.game, x, y, key, frame, bodyType));
|
||||
};
|
||||
Group.prototype.setObjectIDs = /**
|
||||
@@ -8189,7 +8198,7 @@ var Phaser;
|
||||
*/
|
||||
function (object, splice) {
|
||||
if (typeof splice === "undefined") { splice = false; }
|
||||
console.log('removing from group');
|
||||
console.log('removing from group: ', object.name);
|
||||
this._i = this.members.indexOf(object);
|
||||
if(this._i < 0 || (this._i >= this.members.length)) {
|
||||
return null;
|
||||
@@ -8342,6 +8351,10 @@ var Phaser;
|
||||
* @return {number} An integer value: -1 (Obj1 before Obj2), 0 (same), or 1 (Obj1 after Obj2).
|
||||
*/
|
||||
function (obj1, obj2) {
|
||||
if(!obj1 || !obj2) {
|
||||
//console.log('null objects in sort', obj1, obj2);
|
||||
return 0;
|
||||
}
|
||||
if(obj1[this._sortIndex] < obj2[this._sortIndex]) {
|
||||
return this._sortOrder;
|
||||
} else if(obj1[this._sortIndex] > obj2[this._sortIndex]) {
|
||||
@@ -14135,6 +14148,16 @@ var Phaser;
|
||||
function (sprite) {
|
||||
return this._world.group.add(sprite);
|
||||
};
|
||||
GameObjectFactory.prototype.existingGroup = /**
|
||||
* Add an existing Group to the current world.
|
||||
* Note: This doesn't check or update the objects reference to Game. If that is wrong, all kinds of things will break.
|
||||
*
|
||||
* @param group The Group to add to the Game World
|
||||
* @return {Phaser.Group} The Group object
|
||||
*/
|
||||
function (group) {
|
||||
return this._world.group.add(group);
|
||||
};
|
||||
GameObjectFactory.prototype.existingButton = /**
|
||||
* Add an existing Button to the current world.
|
||||
* Note: This doesn't check or update the objects reference to Game. If that is wrong, all kinds of things will break.
|
||||
@@ -17621,7 +17644,9 @@ var Phaser;
|
||||
//this.game.input.y = this.y * this.game.input.scale.y;
|
||||
this.game.input.x = this.x;
|
||||
this.game.input.y = this.y;
|
||||
this.game.input.position.setTo(this.x, this.y);
|
||||
this.game.input.onDown.dispatch(this);
|
||||
this.game.input.resetSpeed(this.x, this.y);
|
||||
}
|
||||
this._stateReset = false;
|
||||
this.totalTouches++;
|
||||
@@ -18934,6 +18959,10 @@ var Phaser;
|
||||
this.totalTrackedObjects = 0;
|
||||
}
|
||||
};
|
||||
Input.prototype.resetSpeed = function (x, y) {
|
||||
this._oldPosition.setTo(x, y);
|
||||
this.speed.setTo(0, 0);
|
||||
};
|
||||
Object.defineProperty(Input.prototype, "totalInactivePointers", {
|
||||
get: /**
|
||||
* Get the total number of inactive Pointers
|
||||
@@ -19870,6 +19899,24 @@ var Phaser;
|
||||
DebugUtils.context.fillStyle = fillStyle;
|
||||
DebugUtils.context.fillRect(rect.x, rect.y, rect.width, rect.height);
|
||||
};
|
||||
DebugUtils.renderCircle = function renderCircle(circle, fillStyle) {
|
||||
if (typeof fillStyle === "undefined") { fillStyle = 'rgba(0,255,0,0.3)'; }
|
||||
DebugUtils.context.fillStyle = fillStyle;
|
||||
DebugUtils.context.arc(circle.x, circle.y, circle.radius, 0, Math.PI * 2, false);
|
||||
DebugUtils.context.fill();
|
||||
};
|
||||
DebugUtils.renderText = /**
|
||||
* Render text
|
||||
* @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)
|
||||
*/
|
||||
function renderText(text, x, y, color) {
|
||||
if (typeof color === "undefined") { color = 'rgb(255,255,255)'; }
|
||||
DebugUtils.context.font = '16px Courier';
|
||||
DebugUtils.context.fillStyle = color;
|
||||
DebugUtils.context.fillText(text, x, y);
|
||||
};
|
||||
DebugUtils.renderPhysicsBody = function renderPhysicsBody(body, lineWidth, fillStyle, sleepStyle) {
|
||||
if (typeof lineWidth === "undefined") { lineWidth = 1; }
|
||||
if (typeof fillStyle === "undefined") { fillStyle = 'rgba(0,255,0,0.2)'; }
|
||||
@@ -20760,15 +20807,10 @@ var Phaser;
|
||||
function contains(a, x, y) {
|
||||
// Check if x/y are within the bounds first
|
||||
if(x >= a.left && x <= a.right && y >= a.top && y <= a.bottom) {
|
||||
var dx = a.x - x;
|
||||
var dy = a.y - y;
|
||||
dx *= dx;
|
||||
dy *= dy;
|
||||
var radSqr = a.radius * a.radius;
|
||||
console.log('within bounds', dx, dy, radSqr);
|
||||
return (dx + dy) <= radSqr;
|
||||
//return (a.left * a.left + a.top * a.top) <= (a.radius * a.radius);
|
||||
}
|
||||
var dx = (a.x - x) * (a.x - x);
|
||||
var dy = (a.y - y) * (a.y - y);
|
||||
return (dx + dy) <= (a.radius * a.radius);
|
||||
}
|
||||
return false;
|
||||
};
|
||||
CircleUtils.containsPoint = /**
|
||||
|
||||
Vendored
+56
-4
@@ -3342,11 +3342,21 @@ module Phaser {
|
||||
*/
|
||||
public rotation : number;
|
||||
/**
|
||||
* Brings this Sprite to the top of its current Group, if set.
|
||||
*/
|
||||
public bringToTop(): void;
|
||||
/**
|
||||
* The scale of the Sprite. A value of 1 is original scale. 0.5 is half size. 2 is double the size.
|
||||
* This is a reference to Sprite.transform.scale
|
||||
*/
|
||||
public scale: Vec2;
|
||||
/**
|
||||
* The crop rectangle allows you to control which part of the sprite texture is rendered without distorting it.
|
||||
* Set to null to disable, set to a Phaser.Rectangle object to control the region that will be rendered, anything outside the rectangle is ignored.
|
||||
* @type {Phaser.Rectangle}
|
||||
*/
|
||||
public crop: Rectangle;
|
||||
/**
|
||||
* The origin of the Sprite around which rotation and positioning takes place.
|
||||
* This is a reference to Sprite.transform.origin
|
||||
*/
|
||||
@@ -3600,6 +3610,12 @@ module Phaser.Components {
|
||||
*/
|
||||
public isDynamic: bool;
|
||||
/**
|
||||
* The crop rectangle allows you to control which part of the sprite texture is rendered without distorting it.
|
||||
* Set to null to disable, set to a Phaser.Rectangle object to control the region that will be rendered, anything outside the rectangle is ignored.
|
||||
* @type {Phaser.Rectangle}
|
||||
*/
|
||||
public crop: Rectangle;
|
||||
/**
|
||||
* Updates the texture being used to render the Sprite.
|
||||
* Called automatically by SpriteUtils.loadTexture and SpriteUtils.loadDynamicTexture.
|
||||
*/
|
||||
@@ -3732,7 +3748,7 @@ module Phaser {
|
||||
public getNextZIndex(): number;
|
||||
/**
|
||||
* Override this function to handle any deleting or "shutdown" type operations you might need,
|
||||
* such as removing traditional Flash children like Basic objects.
|
||||
* such as removing traditional children like Basic objects.
|
||||
*/
|
||||
public destroy(): void;
|
||||
/**
|
||||
@@ -3782,7 +3798,7 @@ module Phaser {
|
||||
* @param y {number} Y position of the new sprite.
|
||||
* @param [key] {string} The image key as defined in the Game.Cache to use as the texture for this sprite
|
||||
* @param [frame] {string|number} If the sprite uses an image from a texture atlas or sprite sheet you can pass the frame here. Either a number for a frame ID or a string for a frame name.
|
||||
* @param [bodyType] {number} The physics body type of the object (defaults to BODY_DYNAMIC)
|
||||
* @param [bodyType] {number} The physics body type of the object (defaults to BODY_DISABLED)
|
||||
* @returns {Sprite} The newly created sprite object.
|
||||
*/
|
||||
public addNewSprite(x: number, y: number, key?: string, frame?, bodyType?: number): Sprite;
|
||||
@@ -6956,6 +6972,14 @@ module Phaser {
|
||||
*/
|
||||
public existingSprite(sprite: Sprite): Sprite;
|
||||
/**
|
||||
* Add an existing Group to the current world.
|
||||
* Note: This doesn't check or update the objects reference to Game. If that is wrong, all kinds of things will break.
|
||||
*
|
||||
* @param group The Group to add to the Game World
|
||||
* @return {Phaser.Group} The Group object
|
||||
*/
|
||||
public existingGroup(group: Group): Group;
|
||||
/**
|
||||
* Add an existing Button to the current world.
|
||||
* Note: This doesn't check or update the objects reference to Game. If that is wrong, all kinds of things will break.
|
||||
*
|
||||
@@ -7693,6 +7717,11 @@ module Phaser {
|
||||
*/
|
||||
public scaleMode: number;
|
||||
/**
|
||||
* If set to true the game will never pause when the browser or browser tab loses focuses
|
||||
* @type {boolean}
|
||||
*/
|
||||
public disableVisibilityChange: bool;
|
||||
/**
|
||||
* Stage boot
|
||||
*/
|
||||
public boot(): void;
|
||||
@@ -9571,6 +9600,8 @@ module Phaser {
|
||||
* @type {Pointer}
|
||||
**/
|
||||
public activePointer: Pointer;
|
||||
public inputObjects: any[];
|
||||
public totalTrackedObjects: number;
|
||||
/**
|
||||
* The X coordinate of the most recently active pointer.
|
||||
* This value takes game scaling into account automatically. See Pointer.screenX/clientX for source values.
|
||||
@@ -9597,8 +9628,6 @@ module Phaser {
|
||||
* @method start
|
||||
**/
|
||||
public boot(): void;
|
||||
public inputObjects: any[];
|
||||
public totalTrackedObjects: number;
|
||||
/**
|
||||
* Adds a new game object to be tracked by the Input Manager. Called by the Sprite.Input component, should not usually be called directly.
|
||||
* @method addGameObject
|
||||
@@ -9620,6 +9649,7 @@ module Phaser {
|
||||
* @param hard {Boolean} A soft reset (hard = false) won't reset any signals that might be bound. A hard reset will.
|
||||
**/
|
||||
public reset(hard?: bool): void;
|
||||
public resetSpeed(x: number, y: number): void;
|
||||
/**
|
||||
* Get the total number of inactive Pointers
|
||||
* @method totalInactivePointers
|
||||
@@ -9822,6 +9852,14 @@ module Phaser {
|
||||
static renderPhysicsBodyInfo(body: Physics.Body, x: number, y: number, color?: string): void;
|
||||
static renderSpriteBounds(sprite: Sprite, camera?: Camera, color?: string): void;
|
||||
static renderRectangle(rect: Rectangle, fillStyle?: string): void;
|
||||
static renderCircle(circle: Circle, fillStyle?: string): void;
|
||||
/**
|
||||
* Render text
|
||||
* @param x {number} X position of the debug info to be rendered.
|
||||
* @param y {number} Y position of the debug info to be rendered.
|
||||
* @param [color] {number} color of the debug info to be rendered. (format is css color string)
|
||||
*/
|
||||
static renderText(text: string, x: number, y: number, color?: string): void;
|
||||
static renderPhysicsBody(body: Physics.Body, lineWidth?: number, fillStyle?: string, sleepStyle?: string): void;
|
||||
}
|
||||
}
|
||||
@@ -10378,6 +10416,20 @@ module Phaser {
|
||||
static normalFromMat4(): void;
|
||||
}
|
||||
}
|
||||
interface IPoint {
|
||||
getDist(): number;
|
||||
}
|
||||
module Shapes {
|
||||
class Point implements IPoint {
|
||||
public x: number;
|
||||
public y: number;
|
||||
constructor(x: number, y: number);
|
||||
public getDist(): number;
|
||||
static origin: Point;
|
||||
}
|
||||
}
|
||||
var p: IPoint;
|
||||
var dist: number;
|
||||
/**
|
||||
* Phaser - PixelUtils
|
||||
*
|
||||
|
||||
+1569
-465
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user