First pass at integrating the new physics system.

This commit is contained in:
Richard Davey
2013-05-29 21:39:08 +01:00
parent f3c9049e76
commit c1eafe865a
15 changed files with 2405 additions and 1333 deletions
+9
View File
@@ -61,6 +61,7 @@
<Content Include="components\animation\AnimationManager.js">
<DependentUpon>AnimationManager.ts</DependentUpon>
</Content>
<TypeScriptCompile Include="components\sprite\Physics.ts" />
<TypeScriptCompile Include="core\Rectangle.ts" />
<TypeScriptCompile Include="core\Point.ts" />
<TypeScriptCompile Include="components\sprite\Texture.ts" />
@@ -107,6 +108,14 @@
<TypeScriptCompile Include="renderers\CanvasRenderer.ts" />
<TypeScriptCompile Include="Statics.ts" />
<TypeScriptCompile Include="renderers\HeadlessRenderer.ts" />
<TypeScriptCompile Include="physics\PhysicsManager.ts" />
<TypeScriptCompile Include="physics\AABB.ts" />
<Content Include="physics\AABB.js">
<DependentUpon>AABB.ts</DependentUpon>
</Content>
<Content Include="physics\PhysicsManager.js">
<DependentUpon>PhysicsManager.ts</DependentUpon>
</Content>
<Content Include="renderers\HeadlessRenderer.js">
<DependentUpon>HeadlessRenderer.ts</DependentUpon>
</Content>
+17 -2
View File
@@ -2,6 +2,7 @@
/// <reference path="cameras/CameraManager.ts" />
/// <reference path="core/Group.ts" />
/// <reference path="core/Rectangle.ts" />
/// <reference path="physics/PhysicsManager.ts" />
/**
* Phaser - World
@@ -34,6 +35,8 @@ module Phaser {
this.bounds = new Rectangle(0, 0, width, height);
this.physics = new Physics.PhysicsManager(this._game, width, height);
this.worldDivisions = 6;
}
@@ -61,6 +64,12 @@ module Phaser {
*/
public bounds: Rectangle;
/**
* Reference to the physics manager.
* @type {Physics.PhysicsManager}
*/
public physics: Physics.PhysicsManager;
/**
* @type {number}
*/
@@ -71,6 +80,7 @@ module Phaser {
*/
public update() {
this.physics.update();
this.group.update();
this.cameras.update();
@@ -81,8 +91,8 @@ module Phaser {
*/
public destroy() {
//this.physics.destroy();
this.group.destroy();
this.cameras.destroy();
}
@@ -94,7 +104,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) {
public setSize(width: number, height: number, updateCameraBounds: bool = true, updatePhysicsBounds: bool = true) {
this.bounds.width = width;
this.bounds.height = height;
@@ -104,6 +114,11 @@ module Phaser {
this._game.camera.setBounds(0, 0, width, height);
}
if (updatePhysicsBounds == true)
{
//this.physics.bounds.copyFrom(this.bounds);
}
// dispatch world resize event
}
+46 -17
View File
@@ -1,5 +1,6 @@
/// <reference path="../../core/Vec2.ts" />
/// <reference path="../../core/Point.ts" />
/// <reference path="../../physics/AABB.ts" />
/**
* Phaser - Components - Physics
@@ -11,6 +12,28 @@ module Phaser.Components {
export class Physics {
constructor(parent: Sprite) {
this._game = parent.game;
this._sprite = parent;
//this.AABB = new Phaser.Physics.AABB(this._game, this._sprite, this._sprite.x, this._sprite.y, this._sprite.width, this._sprite.height);
this.AABB = this._game.world.physics.add(new Phaser.Physics.AABB(this._game, this._sprite, this._sprite.x, this._sprite.y, this._sprite.width, this._sprite.height));
}
/**
*
*/
private _game: Game;
/**
*
*/
private _sprite: Sprite;
public AABB: Phaser.Physics.AABB;
/**
* Whether this object will be moved by impacts with other objects or not.
* @type {boolean}
@@ -126,9 +149,9 @@ module Phaser.Components {
*
* @return {boolean} Whether the object is touching an object in (any of) the specified direction(s) this frame.
*/
public isTouching(direction: number): bool {
return (this.touching & direction) > Collision.NONE;
}
//public isTouching(direction: number): bool {
// return (this.touching & direction) > Collision.NONE;
//}
/**
* Handy function for checking if this object just landed on a particular surface.
@@ -137,9 +160,9 @@ module Phaser.Components {
*
* @returns {boolean} Whether the object just landed on any specicied surfaces.
*/
public justTouched(direction: number): bool {
return ((this.touching & direction) > Collision.NONE) && ((this.wasTouching & direction) <= Collision.NONE);
}
//public justTouched(direction: number): bool {
// return ((this.touching & direction) > Collision.NONE) && ((this.wasTouching & direction) <= Collision.NONE);
//}
/**
@@ -147,6 +170,12 @@ module Phaser.Components {
*/
public update() {
if (this.moves)
{
this._sprite.x = this.AABB.position.x - this.AABB.halfWidth;
this._sprite.y = this.AABB.position.y - this.AABB.halfHeight;
}
/*
var delta: number;
var velocityDelta: number;
@@ -176,20 +205,20 @@ module Phaser.Components {
* the object will collide from, use collision constants (like LEFT, FLOOR, etc)
* to set the value of allowCollisions directly.
*/
public get solid(): bool {
return (this.allowCollisions & Collision.ANY) > Collision.NONE;
}
//public get solid(): bool {
// return (this.allowCollisions & Collision.ANY) > Collision.NONE;
//}
public set solid(value: bool) {
if (value)
{
this.allowCollisions = Collision.ANY;
}
else
{
this.allowCollisions = Collision.NONE;
}
//if (value)
//{
// this.allowCollisions = Collision.ANY;
//}
//else
//{
// this.allowCollisions = Collision.NONE;
//}
}
+14
View File
@@ -1,5 +1,6 @@
/// <reference path="../Game.ts" />
/// <reference path="../tweens/Tween.ts" />
/// <reference path="../physics/AABB.ts" />
/**
* Phaser - GameObjectFactory
@@ -89,6 +90,19 @@ module Phaser {
return <Group> this._world.group.add(new Group(this._game, maxSize));
}
/**
* Create a new Sprite with specific position and sprite sheet key.
*
* @param x {number} X position of the new sprite.
* @param y {number} Y position of the new sprite.
* @param key {string} Optional, key for the sprite sheet you want it to use.
* @returns {Sprite} The newly created sprite object.
* WILL NEED TO TRACK A SPRITE
*/
public physicsAABB(x: number, y: number, width: number, height: number): Physics.AABB {
return <Physics.AABB> this._world.physics.add(new Physics.AABB(this._game, null, x, y, width, height));
}
/**
* Create a new Particle.
*
+11 -9
View File
@@ -3,6 +3,7 @@
/// <reference path="../core/Rectangle.ts" />
/// <reference path="../components/animation/AnimationManager.ts" />
/// <reference path="../components/sprite/Texture.ts" />
/// <reference path="../components/sprite/Physics.ts" />
/**
* Phaser - Sprite
@@ -47,6 +48,8 @@ module Phaser {
this.width = this.frameBounds.width;
this.height = this.frameBounds.height;
this.physics = new Phaser.Components.Physics(this);
// Transform related (if we add any more then move to a component)
this.origin = new Phaser.Vec2(0, 0);
this.scale = new Phaser.Vec2(1, 1);
@@ -99,6 +102,11 @@ module Phaser {
public width: number;
public height: number;
/**
* Sprite physics.
*/
public physics: Phaser.Components.Physics;
/**
* The texture used to render the Sprite.
*/
@@ -213,10 +221,8 @@ module Phaser {
*/
public preUpdate() {
//this.last.x = this.frameBounds.x;
//this.last.y = this.frameBounds.y;
//this.collisionMask.preUpdate();
this.frameBounds.x = this.x;
this.frameBounds.y = this.y;
if (this.modified == false && (!this.scale.equals(1) || !this.skew.equals(0) || this.rotation != 0 || this.rotationOffset != 0 || this.texture.flippedX || this.texture.flippedY))
{
@@ -237,13 +243,9 @@ module Phaser {
public postUpdate() {
this.animations.update();
this.physics.update();
/*
if (this.moves)
{
this.updateMotion();
}
if (this.worldBounds != null)
{
if (this.outOfBoundsAction == GameObject.OUT_OF_BOUNDS_KILL)
+155
View File
@@ -0,0 +1,155 @@
/// <reference path="../Game.ts" />
/// <reference path="PhysicsManager.ts" />
/**
* Phaser - Physics - AABB
*/
module Phaser.Physics {
export class AABB {
constructor(game: Game, sprite: Sprite, x: number, y: number, width: number, height: number) {
this.game = game;
this.world = game.world.physics;
this.sprite = sprite;
this.width = width;
this.height = height;
this.halfWidth = Math.round(width / 2);
this.halfHeight = Math.round(height / 2);
this.position = new Vec2(x + this.halfWidth, y + this.halfHeight);
this.oldPosition = new Vec2(x + this.halfWidth, y + this.halfHeight);
}
/**
* Local private reference to Game.
*/
public game: Game;
public world: PhysicsManager;
public sprite: Sprite;
public position: Vec2;
public oldPosition: Vec2;
public width: number;
public height: number;
public halfWidth: number;
public halfHeight: number;
public update() {
if (this.sprite.physics.moves)
{
this.integrate();
this.collideWorld();
}
}
private integrate() {
var ox: number = this.oldPosition.x;
var oy: number = this.oldPosition.y;
this.oldPosition.x = this.position.x;
this.oldPosition.y = this.position.y;
//this.position.x += (this.world.drag.x * this.position.x + this.halfWidth) - (this.world.drag.x * ox) + this.world.gravity.x;
//this.position.y += (this.world.drag.y * this.position.y + this.halfHeight) - (this.world.drag.y * oy) + this.world.gravity.y;
this.position.x += (this.world.drag.x * this.position.x) - (this.world.drag.x * ox) + this.world.gravity.x;
this.position.y += (this.world.drag.y * this.position.y) - (this.world.drag.y * oy) + this.world.gravity.y;
}
private collideWorld() {
// Collide on the x-axis
var dx: number = this.world.bounds.x - (this.position.x - this.halfWidth);
if (0 < dx)
{
this.processWorld(dx, 0, 1, 0, null);
}
else
{
dx = (this.position.x + this.halfWidth) - this.world.bounds.right;
if (0 < dx)
{
this.processWorld(-dx, 0, -1, 0, null);
}
}
// Collide on the y-axis
var dy: number = this.world.bounds.y - (this.position.y - this.halfHeight);
if (0 < dy)
{
this.processWorld(0, dy, 0, 1, null);
}
else
{
dy = (this.position.y + this.halfHeight) - this.world.bounds.bottom;
if (0 < dy)
{
this.processWorld(0, -dy, 0, -1, null);
}
}
}
private processWorld(px, py, dx, dy, tile) {
// Velocity
var vx: number = this.position.x - this.oldPosition.x;
var vy: number = this.position.y - this.oldPosition.y;
var dp: number = (vx * dx + vy * dy);
var nx: number = dp * dx;
var ny: number = dp * dy;
var tx: number = vx - nx;
var ty: number = vy - ny;
var b, bx, by, f, fx, fy;
if (dp < 0)
{
fx = tx * this.world.friction.x;
fy = ty * this.world.friction.y;
bx = (nx * (1 + this.world.bounce.x));
by = (ny * (1 + this.world.bounce.y));
}
else
{
bx = by = fx = fy = 0;
}
this.position.x += px;
this.position.y += py;
this.oldPosition.x += px + bx + fx;
this.oldPosition.y += py + by + fy;
}
public render(context:CanvasRenderingContext2D) {
context.beginPath();
context.strokeStyle = 'rgb(0,255,0)';
context.strokeRect(this.position.x - this.halfWidth, this.position.y - this.halfHeight, this.width, this.height);
context.stroke();
context.closePath();
// center point
context.fillStyle = 'rgb(0,255,0)';
context.fillRect(this.position.x, this.position.y, 2, 2);
}
}
}
+83
View File
@@ -0,0 +1,83 @@
/// <reference path="../Game.ts" />
/**
* Phaser - PhysicsManager
*
* 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.
*/
module Phaser.Physics {
export class PhysicsManager {
constructor(game: Game, width: number, height: number) {
this._game = game;
this.gravity = new Vec2(0, 0.2);
this.drag = new Vec2(1, 1);
this.bounce = new Vec2(0.3, 0.7);
this.friction = new Vec2(0.05, 0.05);
this.bounds = new Rectangle(0, 0, width, height);
this._objects = [];
}
/**
* Local private reference to Game.
*/
private _game: Game;
private _objects;
public bounds: Rectangle;
public gravity: Vec2;
public drag: Vec2;
public bounce: Vec2;
public friction: Vec2;
private minFriction: number = 0;
private maxFriction: number = 1;
private minBounce: number = 0;
private maxBounce: number = 1;
private minGravity: number = 0;
private maxGravity: number = 1;
private _i: number = 0;
private _length: number = 0;
public add(o) {
this._objects.push(o);
this._length++;
return o;
}
public update() {
// iterate through the objects here, updating and colliding
for (this._i = 0; this._i < this._length; this._i++)
{
this._objects[this._i].update();
}
}
public render() {
// iterate through the objects here, updating and colliding
for (this._i = 0; this._i < this._length; this._i++)
{
this._objects[this._i].render(this._game.stage.context);
}
}
}
}
+3
View File
@@ -53,6 +53,9 @@ module Phaser {
this._camera.postRender();
}
// Physics Debug layer
this._game.world.physics.render();
}
/**
+4
View File
@@ -65,6 +65,10 @@
<Content Include="cameras\scrollfactor 2.js">
<DependentUpon>scrollfactor 2.ts</DependentUpon>
</Content>
<TypeScriptCompile Include="physics\aabb 1.ts" />
<Content Include="physics\aabb 1.js">
<DependentUpon>aabb 1.ts</DependentUpon>
</Content>
<Content Include="tweens\tween loop 1.js">
<DependentUpon>tween loop 1.ts</DependentUpon>
</Content>
+1 -2
View File
@@ -11,8 +11,7 @@
var temp = game.add.sprite(600 + (10 * i), 200 + (10 * i), 'disk');
temp.scrollFactor.setTo(i / 2, i / 2);
}
//game.camera.focusOnXY(800, 200);
}
}
function update() {
if(game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
game.camera.scroll.x -= 4;
+757 -494
View File
File diff suppressed because it is too large Load Diff
+17
View File
@@ -0,0 +1,17 @@
/// <reference path="../../Phaser/Game.ts" />
(function () {
var game = new Phaser.Game(this, 'game', 800, 600, init, create, update);
function init() {
// Using Phasers asset loader we load up a PNG from the assets folder
game.loader.addImageFile('bunny', 'assets/sprites/atari800xl.png');
game.loader.load();
}
var atari;
function create() {
atari = game.add.sprite(200, 200, 'bunny');
//game.add.physicsAABB(200, 200, 233, 99);
}
function update() {
//atari.y += 0.2;
}
})();
+26
View File
@@ -0,0 +1,26 @@
/// <reference path="../../Phaser/Game.ts" />
(function () {
var game = new Phaser.Game(this, 'game', 800, 600, init, create, update);
function init() {
// Using Phasers asset loader we load up a PNG from the assets folder
game.loader.addImageFile('atari', 'assets/sprites/atari800xl.png');
game.loader.load();
}
var atari: Phaser.Sprite;
function create() {
atari = game.add.sprite(200, 200, 'atari');
}
function update() {
}
})();
+505 -315
View File
@@ -949,146 +949,228 @@ module Phaser {
}
}
/**
* Phaser - Vec2
* Phaser - Point
*
* A Circle object is an area defined by its position, as indicated by its center point (x,y) and diameter.
* The Point object represents a location in a two-dimensional coordinate system, where x represents the horizontal axis and y represents the vertical axis.
*/
module Phaser {
class Vec2 {
class Point {
/**
* Creates a new Vec2 object.
* @class Vec2
* Creates a new Point. If you pass no parameters a Point is created set to (0,0).
* @class Point
* @constructor
* @param {Number} x The x position of the vector
* @param {Number} y The y position of the vector
* @return {Vec2} This object
* @param {Number} x The horizontal position of this Point (default 0)
* @param {Number} y The vertical position of this Point (default 0)
**/
constructor(x?: number, y?: number);
public x: number;
public y: number;
/**
* The x coordinate of the vector
* Copies the x and y properties from any given object to this Point.
* @method copyFrom
* @param {any} source - The object to copy from.
* @return {Point} This Point object.
**/
public copyFrom(source: any): Point;
/**
* Inverts the x and y values of this Point
* @method invert
* @return {Point} This Point object.
**/
public invert(): Point;
/**
* Sets the x and y values of this MicroPoint object to the given coordinates.
* @method setTo
* @param {Number} x - The horizontal position of this point.
* @param {Number} y - The vertical position of this point.
* @return {MicroPoint} This MicroPoint object. Useful for chaining method calls.
**/
public setTo(x: number, y: number): Point;
/**
* Returns a string representation of this object.
* @method toString
* @return {string} a string representation of the instance.
**/
public toString(): string;
}
}
/**
* Rectangle
*
* @desc A Rectangle object is an area defined by its position, as indicated by its top-left corner (x,y) and width and height.
*
* @version 1.6 - 24th May 2013
* @author Richard Davey
*/
module Phaser {
class Rectangle {
/**
* Creates a new Rectangle object with the top-left corner specified by the x and y parameters and with the specified width and height parameters. If you call this function without parameters, a rectangle with x, y, width, and height properties set to 0 is created.
* @class Rectangle
* @constructor
* @param {Number} x The x coordinate of the top-left corner of the rectangle.
* @param {Number} y The y coordinate of the top-left corner of the rectangle.
* @param {Number} width The width of the rectangle in pixels.
* @param {Number} height The height of the rectangle in pixels.
* @return {Rectangle} This rectangle object
**/
constructor(x?: number, y?: number, width?: number, height?: number);
/**
* The x coordinate of the top-left corner of the rectangle
* @property x
* @type Number
**/
public x: number;
/**
* The y coordinate of the vector
* The y coordinate of the top-left corner of the rectangle
* @property y
* @type Number
**/
public y: number;
/**
* Copies the x and y properties from any given object to this Vec2.
* The width of the rectangle in pixels
* @property width
* @type Number
**/
public width: number;
/**
* The height of the rectangle in pixels
* @property height
* @type Number
**/
public height: number;
/**
* Half of the width of the rectangle
* @property halfWidth
* @type Number
**/
public halfWidth : number;
/**
* Half of the height of the rectangle
* @property halfHeight
* @type Number
**/
public halfHeight : number;
/**
* The sum of the y and height properties. Changing the bottom property of a Rectangle object has no effect on the x, y and width properties, but does change the height property.
* @method bottom
* @return {Number}
**/
/**
* The sum of the y and height properties. Changing the bottom property of a Rectangle object has no effect on the x, y and width properties, but does change the height property.
* @method bottom
* @param {Number} value
**/
public bottom : number;
/**
* Sets the bottom-right corner of the Rectangle, determined by the values of the given Point object.
* @method bottomRight
* @param {Point} value
**/
public bottomRight : Point;
/**
* The x coordinate of the left of the Rectangle. Changing the left property of a Rectangle object has no effect on the y and height properties. However it does affect the width property, whereas changing the x value does not affect the width property.
* @method left
* @ return {number}
**/
/**
* The x coordinate of the left of the Rectangle. Changing the left property of a Rectangle object has no effect on the y and height properties.
* However it does affect the width, whereas changing the x value does not affect the width property.
* @method left
* @param {Number} value
**/
public left : number;
/**
* The sum of the x and width properties. Changing the right property of a Rectangle object has no effect on the x, y and height properties.
* However it does affect the width property.
* @method right
* @return {Number}
**/
/**
* The sum of the x and width properties. Changing the right property of a Rectangle object has no effect on the x, y and height properties.
* However it does affect the width property.
* @method right
* @param {Number} value
**/
public right : number;
/**
* The volume of the Rectangle derived from width * height
* @method volume
* @return {Number}
**/
public volume : number;
/**
* The perimeter size of the Rectangle. This is the sum of all 4 sides.
* @method perimeter
* @return {Number}
**/
public perimeter : number;
/**
* The y coordinate of the top of the Rectangle. Changing the top property of a Rectangle object has no effect on the x and width properties.
* However it does affect the height property, whereas changing the y value does not affect the height property.
* @method top
* @return {Number}
**/
/**
* The y coordinate of the top of the Rectangle. Changing the top property of a Rectangle object has no effect on the x and width properties.
* However it does affect the height property, whereas changing the y value does not affect the height property.
* @method top
* @param {Number} value
**/
public top : number;
/**
* The location of the Rectangles top-left corner, determined by the x and y coordinates of the Point.
* @method topLeft
* @param {Point} value
**/
public topLeft : Point;
/**
* Determines whether or not this Rectangle object is empty.
* @method isEmpty
* @return {Boolean} A value of true if the Rectangle object's width or height is less than or equal to 0; otherwise false.
**/
/**
* Sets all of the Rectangle object's properties to 0. A Rectangle object is empty if its width or height is less than or equal to 0.
* @method setEmpty
* @return {Rectangle} This rectangle object
**/
public empty : bool;
/**
* Adjusts the location of the Rectangle object, as determined by its top-left corner, by the specified amounts.
* @method offset
* @param {Number} dx Moves the x value of the Rectangle object by this amount.
* @param {Number} dy Moves the y value of the Rectangle object by this amount.
* @return {Rectangle} This Rectangle object.
**/
public offset(dx: number, dy: number): Rectangle;
/**
* Adjusts the location of the Rectangle object using a Point object as a parameter. This method is similar to the Rectangle.offset() method, except that it takes a Point object as a parameter.
* @method offsetPoint
* @param {Point} point A Point object to use to offset this Rectangle object.
* @return {Rectangle} This Rectangle object.
**/
public offsetPoint(point: Point): Rectangle;
/**
* Sets the members of Rectangle to the specified values.
* @method setTo
* @param {Number} x The x coordinate of the top-left corner of the rectangle.
* @param {Number} y The y coordinate of the top-left corner of the rectangle.
* @param {Number} width The width of the rectangle in pixels.
* @param {Number} height The height of the rectangle in pixels.
* @return {Rectangle} This rectangle object
**/
public setTo(x: number, y: number, width: number, height: number): Rectangle;
/**
* Copies the x, y, width and height properties from any given object to this Rectangle.
* @method copyFrom
* @param {any} source - The object to copy from.
* @return {Vec2} This Vec2 object.
* @return {Rectangle} This Rectangle object.
**/
public copyFrom(source: any): Vec2;
/**
* Sets the x and y properties of the Vector.
* @param {Number} x The x position of the vector
* @param {Number} y The y position of the vector
* @return {Vec2} This object
**/
public setTo(x: number, y: number): Vec2;
/**
* Add another vector to this one.
*
* @param {Vec2} other The other Vector.
* @return {Vec2} This for chaining.
*/
public add(a: Vec2): Vec2;
/**
* Subtract another vector from this one.
*
* @param {Vec2} other The other Vector.
* @return {Vec2} This for chaining.
*/
public subtract(v: Vec2): Vec2;
/**
* Multiply another vector with this one.
*
* @param {Vec2} other The other Vector.
* @return {Vec2} This for chaining.
*/
public multiply(v: Vec2): Vec2;
/**
* Divide this vector by another one.
*
* @param {Vec2} other The other Vector.
* @return {Vec2} This for chaining.
*/
public divide(v: Vec2): Vec2;
/**
* Get the length of this vector.
*
* @return {number} The length of this vector.
*/
public length(): number;
/**
* Get the length squared of this vector.
*
* @return {number} The length^2 of this vector.
*/
public lengthSq(): number;
/**
* The dot product of two 2D vectors.
*
* @param {Vec2} a Reference to a source Vec2 object.
* @return {Number}
*/
public dot(a: Vec2): number;
/**
* The cross product of two 2D vectors.
*
* @param {Vec2} a Reference to a source Vec2 object.
* @return {Number}
*/
public cross(a: Vec2): number;
/**
* The projection magnitude of two 2D vectors.
*
* @param {Vec2} a Reference to a source Vec2 object.
* @return {Number}
*/
public projectionLength(a: Vec2): number;
/**
* The angle between two 2D vectors.
*
* @param {Vec2} a Reference to a source Vec2 object.
* @return {Number}
*/
public angle(a: Vec2): number;
/**
* Scale this vector.
*
* @param {number} x The scaling factor in the x direction.
* @param {?number=} y The scaling factor in the y direction. If this is not specified, the x scaling factor will be used.
* @return {Vec2} This for chaining.
*/
public scale(x: number, y?: number): Vec2;
/**
* Divide this vector by the given scalar.
*
* @param {number} scalar
* @return {Vec2} This for chaining.
*/
public divideByScalar(scalar: number): Vec2;
/**
* Reverse this vector.
*
* @return {Vec2} This for chaining.
*/
public reverse(): Vec2;
/**
* Check if both the x and y of this vector equal the given value.
*
* @return {Boolean}
*/
public equals(value): bool;
public copyFrom(source: any): Rectangle;
/**
* Returns a string representation of this object.
* @method toString
* @return {string} a string representation of the object.
* @return {string} a string representation of the instance.
**/
public toString(): string;
}
@@ -2221,6 +2303,10 @@ module Phaser {
public width: number;
public height: number;
/**
* Sprite physics.
*/
public physics: Components.Physics;
/**
* The texture used to render the Sprite.
*/
public texture: Components.Texture;
@@ -2933,6 +3019,63 @@ module Phaser {
}
}
/**
* Phaser - PhysicsManager
*
* 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.
*/
module Phaser.Physics {
class PhysicsManager {
constructor(game: Game, width: number, height: number);
/**
* Local private reference to Game.
*/
private _game;
private _objects;
public bounds: Rectangle;
public gravity: Vec2;
public drag: Vec2;
public bounce: Vec2;
public friction: Vec2;
private minFriction;
private maxFriction;
private minBounce;
private maxBounce;
private minGravity;
private maxGravity;
private _i;
private _length;
public add(o);
public update(): void;
public render(): void;
}
}
/**
* Phaser - Physics - AABB
*/
module Phaser.Physics {
class AABB {
constructor(game: Game, sprite: Sprite, x: number, y: number, width: number, height: number);
/**
* Local private reference to Game.
*/
public game: Game;
public world: PhysicsManager;
public sprite: Sprite;
public position: Vec2;
public oldPosition: Vec2;
public width: number;
public height: number;
public halfWidth: number;
public halfHeight: number;
public update(): void;
private integrate();
private collideWorld();
private processWorld(px, py, dx, dy, tile);
public render(context: CanvasRenderingContext2D): void;
}
}
/**
* Phaser - GameObjectFactory
*
* A quick way to create new world objects and add existing objects to the current world.
@@ -2987,6 +3130,16 @@ module Phaser {
*/
public group(maxSize?: number): Group;
/**
* Create a new Sprite with specific position and sprite sheet key.
*
* @param x {number} X position of the new sprite.
* @param y {number} Y position of the new sprite.
* @param key {string} Optional, key for the sprite sheet you want it to use.
* @returns {Sprite} The newly created sprite object.
* WILL NEED TO TRACK A SPRITE
*/
public physicsAABB(x: number, y: number, width: number, height: number): Physics.AABB;
/**
* Create a tween object for a specific object.
*
* @param obj Object you wish the tween will affect.
@@ -4291,6 +4444,11 @@ module Phaser {
*/
public bounds: Rectangle;
/**
* Reference to the physics manager.
* @type {Physics.PhysicsManager}
*/
public physics: Physics.PhysicsManager;
/**
* @type {number}
*/
public worldDivisions: number;
@@ -4309,7 +4467,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): void;
public setSize(width: number, height: number, updateCameraBounds?: bool, updatePhysicsBounds?: bool): void;
public width : number;
public height : number;
public centerX : number;
@@ -6102,233 +6260,265 @@ module Phaser {
}
}
/**
* Phaser - Point
* Phaser - Vec2
*
* The Point object represents a location in a two-dimensional coordinate system, where x represents the horizontal axis and y represents the vertical axis.
* A Circle object is an area defined by its position, as indicated by its center point (x,y) and diameter.
*/
module Phaser {
class Point {
class Vec2 {
/**
* Creates a new Point. If you pass no parameters a Point is created set to (0,0).
* @class Point
* Creates a new Vec2 object.
* @class Vec2
* @constructor
* @param {Number} x The horizontal position of this Point (default 0)
* @param {Number} y The vertical position of this Point (default 0)
* @param {Number} x The x position of the vector
* @param {Number} y The y position of the vector
* @return {Vec2} This object
**/
constructor(x?: number, y?: number);
public x: number;
public y: number;
/**
* Copies the x and y properties from any given object to this Point.
* @method copyFrom
* @param {any} source - The object to copy from.
* @return {Point} This Point object.
**/
public copyFrom(source: any): Point;
/**
* Inverts the x and y values of this Point
* @method invert
* @return {Point} This Point object.
**/
public invert(): Point;
/**
* Sets the x and y values of this MicroPoint object to the given coordinates.
* @method setTo
* @param {Number} x - The horizontal position of this point.
* @param {Number} y - The vertical position of this point.
* @return {MicroPoint} This MicroPoint object. Useful for chaining method calls.
**/
public setTo(x: number, y: number): Point;
/**
* Returns a string representation of this object.
* @method toString
* @return {string} a string representation of the instance.
**/
public toString(): string;
}
}
/**
* Rectangle
*
* @desc A Rectangle object is an area defined by its position, as indicated by its top-left corner (x,y) and width and height.
*
* @version 1.6 - 24th May 2013
* @author Richard Davey
*/
module Phaser {
class Rectangle {
/**
* Creates a new Rectangle object with the top-left corner specified by the x and y parameters and with the specified width and height parameters. If you call this function without parameters, a rectangle with x, y, width, and height properties set to 0 is created.
* @class Rectangle
* @constructor
* @param {Number} x The x coordinate of the top-left corner of the rectangle.
* @param {Number} y The y coordinate of the top-left corner of the rectangle.
* @param {Number} width The width of the rectangle in pixels.
* @param {Number} height The height of the rectangle in pixels.
* @return {Rectangle} This rectangle object
**/
constructor(x?: number, y?: number, width?: number, height?: number);
/**
* The x coordinate of the top-left corner of the rectangle
* The x coordinate of the vector
* @property x
* @type Number
**/
public x: number;
/**
* The y coordinate of the top-left corner of the rectangle
* The y coordinate of the vector
* @property y
* @type Number
**/
public y: number;
/**
* The width of the rectangle in pixels
* @property width
* @type Number
**/
public width: number;
/**
* The height of the rectangle in pixels
* @property height
* @type Number
**/
public height: number;
/**
* Half of the width of the rectangle
* @property halfWidth
* @type Number
**/
public halfWidth : number;
/**
* Half of the height of the rectangle
* @property halfHeight
* @type Number
**/
public halfHeight : number;
/**
* The sum of the y and height properties. Changing the bottom property of a Rectangle object has no effect on the x, y and width properties, but does change the height property.
* @method bottom
* @return {Number}
**/
/**
* The sum of the y and height properties. Changing the bottom property of a Rectangle object has no effect on the x, y and width properties, but does change the height property.
* @method bottom
* @param {Number} value
**/
public bottom : number;
/**
* Sets the bottom-right corner of the Rectangle, determined by the values of the given Point object.
* @method bottomRight
* @param {Point} value
**/
public bottomRight : Point;
/**
* The x coordinate of the left of the Rectangle. Changing the left property of a Rectangle object has no effect on the y and height properties. However it does affect the width property, whereas changing the x value does not affect the width property.
* @method left
* @ return {number}
**/
/**
* The x coordinate of the left of the Rectangle. Changing the left property of a Rectangle object has no effect on the y and height properties.
* However it does affect the width, whereas changing the x value does not affect the width property.
* @method left
* @param {Number} value
**/
public left : number;
/**
* The sum of the x and width properties. Changing the right property of a Rectangle object has no effect on the x, y and height properties.
* However it does affect the width property.
* @method right
* @return {Number}
**/
/**
* The sum of the x and width properties. Changing the right property of a Rectangle object has no effect on the x, y and height properties.
* However it does affect the width property.
* @method right
* @param {Number} value
**/
public right : number;
/**
* The volume of the Rectangle derived from width * height
* @method volume
* @return {Number}
**/
public volume : number;
/**
* The perimeter size of the Rectangle. This is the sum of all 4 sides.
* @method perimeter
* @return {Number}
**/
public perimeter : number;
/**
* The y coordinate of the top of the Rectangle. Changing the top property of a Rectangle object has no effect on the x and width properties.
* However it does affect the height property, whereas changing the y value does not affect the height property.
* @method top
* @return {Number}
**/
/**
* The y coordinate of the top of the Rectangle. Changing the top property of a Rectangle object has no effect on the x and width properties.
* However it does affect the height property, whereas changing the y value does not affect the height property.
* @method top
* @param {Number} value
**/
public top : number;
/**
* The location of the Rectangles top-left corner, determined by the x and y coordinates of the Point.
* @method topLeft
* @param {Point} value
**/
public topLeft : Point;
/**
* Determines whether or not this Rectangle object is empty.
* @method isEmpty
* @return {Boolean} A value of true if the Rectangle object's width or height is less than or equal to 0; otherwise false.
**/
/**
* Sets all of the Rectangle object's properties to 0. A Rectangle object is empty if its width or height is less than or equal to 0.
* @method setEmpty
* @return {Rectangle} This rectangle object
**/
public empty : bool;
/**
* Adjusts the location of the Rectangle object, as determined by its top-left corner, by the specified amounts.
* @method offset
* @param {Number} dx Moves the x value of the Rectangle object by this amount.
* @param {Number} dy Moves the y value of the Rectangle object by this amount.
* @return {Rectangle} This Rectangle object.
**/
public offset(dx: number, dy: number): Rectangle;
/**
* Adjusts the location of the Rectangle object using a Point object as a parameter. This method is similar to the Rectangle.offset() method, except that it takes a Point object as a parameter.
* @method offsetPoint
* @param {Point} point A Point object to use to offset this Rectangle object.
* @return {Rectangle} This Rectangle object.
**/
public offsetPoint(point: Point): Rectangle;
/**
* Sets the members of Rectangle to the specified values.
* @method setTo
* @param {Number} x The x coordinate of the top-left corner of the rectangle.
* @param {Number} y The y coordinate of the top-left corner of the rectangle.
* @param {Number} width The width of the rectangle in pixels.
* @param {Number} height The height of the rectangle in pixels.
* @return {Rectangle} This rectangle object
**/
public setTo(x: number, y: number, width: number, height: number): Rectangle;
/**
* Copies the x, y, width and height properties from any given object to this Rectangle.
* Copies the x and y properties from any given object to this Vec2.
* @method copyFrom
* @param {any} source - The object to copy from.
* @return {Rectangle} This Rectangle object.
* @return {Vec2} This Vec2 object.
**/
public copyFrom(source: any): Rectangle;
public copyFrom(source: any): Vec2;
/**
* Sets the x and y properties of the Vector.
* @param {Number} x The x position of the vector
* @param {Number} y The y position of the vector
* @return {Vec2} This object
**/
public setTo(x: number, y: number): Vec2;
/**
* Add another vector to this one.
*
* @param {Vec2} other The other Vector.
* @return {Vec2} This for chaining.
*/
public add(a: Vec2): Vec2;
/**
* Subtract another vector from this one.
*
* @param {Vec2} other The other Vector.
* @return {Vec2} This for chaining.
*/
public subtract(v: Vec2): Vec2;
/**
* Multiply another vector with this one.
*
* @param {Vec2} other The other Vector.
* @return {Vec2} This for chaining.
*/
public multiply(v: Vec2): Vec2;
/**
* Divide this vector by another one.
*
* @param {Vec2} other The other Vector.
* @return {Vec2} This for chaining.
*/
public divide(v: Vec2): Vec2;
/**
* Get the length of this vector.
*
* @return {number} The length of this vector.
*/
public length(): number;
/**
* Get the length squared of this vector.
*
* @return {number} The length^2 of this vector.
*/
public lengthSq(): number;
/**
* The dot product of two 2D vectors.
*
* @param {Vec2} a Reference to a source Vec2 object.
* @return {Number}
*/
public dot(a: Vec2): number;
/**
* The cross product of two 2D vectors.
*
* @param {Vec2} a Reference to a source Vec2 object.
* @return {Number}
*/
public cross(a: Vec2): number;
/**
* The projection magnitude of two 2D vectors.
*
* @param {Vec2} a Reference to a source Vec2 object.
* @return {Number}
*/
public projectionLength(a: Vec2): number;
/**
* The angle between two 2D vectors.
*
* @param {Vec2} a Reference to a source Vec2 object.
* @return {Number}
*/
public angle(a: Vec2): number;
/**
* Scale this vector.
*
* @param {number} x The scaling factor in the x direction.
* @param {?number=} y The scaling factor in the y direction. If this is not specified, the x scaling factor will be used.
* @return {Vec2} This for chaining.
*/
public scale(x: number, y?: number): Vec2;
/**
* Divide this vector by the given scalar.
*
* @param {number} scalar
* @return {Vec2} This for chaining.
*/
public divideByScalar(scalar: number): Vec2;
/**
* Reverse this vector.
*
* @return {Vec2} This for chaining.
*/
public reverse(): Vec2;
/**
* Check if both the x and y of this vector equal the given value.
*
* @return {Boolean}
*/
public equals(value): bool;
/**
* Returns a string representation of this object.
* @method toString
* @return {string} a string representation of the instance.
* @return {string} a string representation of the object.
**/
public toString(): string;
}
}
/**
* Phaser - Components - Physics
*
*
*/
module Phaser.Components {
class Physics {
constructor(parent: Sprite);
/**
*
*/
private _game;
/**
*
*/
private _sprite;
public AABB: Physics.AABB;
/**
* Whether this object will be moved by impacts with other objects or not.
* @type {boolean}
*/
public immovable: bool;
/**
* Basic speed of this object.
*
* Velocity is given in pixels per second. Therefore a velocity of
* 100 will move at a rate of 100 pixels every 1000 ms (1sec). It's not balls-on
* accurate due to the way timers work, but it's pretty close. Expect tolerance
* of +- 10 px. Also that speed assumes no drag.
*
* @type {Vec2}
*/
public velocity: Vec2;
/**
* The virtual mass of the object.
* @type {number}
*/
public mass: number;
/**
* The bounciness of the object.
* @type {number}
*/
public elasticity: number;
/**
* How fast the speed of this object is changing.
* @type {number}
*/
public acceleration: Vec2;
/**
* This isn't drag exactly, more like deceleration that is only applied
* when acceleration is not affecting the sprite.
* @type {Vec2}
*/
public drag: Vec2;
/**
* It will cap the speed automatically if you use the acceleration
* to change its velocity.
* @type {Vec2}
*/
public maxVelocity: Vec2;
/**
* How fast this object is rotating.
* @type {number}
*/
public angularVelocity: number;
/**
* How fast angularVelocity of this object is changing.
* @type {number}
*/
public angularAcceleration: number;
/**
* Deacceleration of angularVelocity will be applied when it's rotating.
* @type {number}
*/
public angularDrag: number;
/**
* It will cap the rotate speed automatically if you use the angularAcceleration
* to change its angularVelocity.
* @type {number}
*/
public maxAngular: number;
/**
* Set this to false if you want to skip the automatic motion/movement stuff
* (see updateMotion()).
* @type {boolean}
*/
public moves: bool;
/**
* Bit field of flags (use with UP, DOWN, LEFT, RIGHT, etc) indicating surface contacts.
* @type {number}
*/
public touching: number;
/**
* Bit field of flags (use with UP, DOWN, LEFT, RIGHT, etc) indicating surface contacts from the previous game loop step.
* @type {number}
*/
public wasTouching: number;
/**
* Bit field of flags (use with UP, DOWN, LEFT, RIGHT, etc) indicating collision directions.
* @type {number}
*/
public allowCollisions: number;
/**
* Important variable for collision processing.
* @type {Vec2}
*/
public last: Vec2;
/**
* Internal function for updating the position and speed of this object.
*/
public update(): void;
public solid : bool;
}
}
/**
* Phaser - CircleUtils
*
* A collection of methods useful for manipulating and comparing Circle objects.
+757 -494
View File
File diff suppressed because it is too large Load Diff