Version 0.9.1 release - see the release notes for more details.

This commit is contained in:
Richard Davey
2013-04-19 18:53:21 +01:00
parent d5229c558a
commit 87e0c483bb
24 changed files with 2050 additions and 781 deletions
+50 -35
View File
@@ -24,10 +24,11 @@ module Phaser {
this.alive = true;
this.isGroup = false;
this.alpha = 1;
this.scale = new Point(1, 1);
this.scale = new MicroPoint(1, 1);
this.last = new Point(x, y);
this.origin = new Point(this.bounds.halfWidth, this.bounds.halfHeight);
this.last = new MicroPoint(x, y);
this.origin = new MicroPoint(this.bounds.halfWidth, this.bounds.halfHeight);
this.align = GameObject.ALIGN_TOP_LEFT;
this.mass = 1.0;
this.elasticity = 0.0;
this.health = 1;
@@ -38,10 +39,10 @@ module Phaser {
this.wasTouching = Collision.NONE;
this.allowCollisions = Collision.ANY;
this.velocity = new Point();
this.acceleration = new Point();
this.drag = new Point();
this.maxVelocity = new Point(10000, 10000);
this.velocity = new MicroPoint();
this.acceleration = new MicroPoint();
this.drag = new MicroPoint();
this.maxVelocity = new MicroPoint(10000, 10000);
this.angle = 0;
this.angularVelocity = 0;
@@ -49,40 +50,58 @@ module Phaser {
this.angularDrag = 0;
this.maxAngular = 10000;
this.scrollFactor = new Point(1.0, 1.0);
this.scrollFactor = new MicroPoint(1.0, 1.0);
}
private _angle: number = 0;
public _point: Point;
public static ALIGN_TOP_LEFT: number = 0;
public static ALIGN_TOP_CENTER: number = 1;
public static ALIGN_TOP_RIGHT: number = 2;
public static ALIGN_CENTER_LEFT: number = 3;
public static ALIGN_CENTER: number = 4;
public static ALIGN_CENTER_RIGHT: number = 5;
public static ALIGN_BOTTOM_LEFT: number = 6;
public static ALIGN_BOTTOM_CENTER: number = 7;
public static ALIGN_BOTTOM_RIGHT: number = 8;
public _point: MicroPoint;
public bounds: Rectangle;
public align: number;
public facing: number;
public alpha: number;
public scale: Point;
public origin: Point;
public scale: MicroPoint;
public origin: MicroPoint;
public z: number = 0;
// Physics properties
public immovable: bool;
public velocity: Point;
// 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
public velocity: MicroPoint;
public mass: number;
public elasticity: number;
public acceleration: Point;
public drag: Point;
public maxVelocity: Point;
public acceleration: MicroPoint;
public drag: MicroPoint;
public maxVelocity: MicroPoint;
public angularVelocity: number;
public angularAcceleration: number;
public angularDrag: number;
public maxAngular: number;
public scrollFactor: Point;
public scrollFactor: MicroPoint;
public health: number;
public moves: bool = true;
public touching: number;
public wasTouching: number;
public allowCollisions: number;
public last: Point;
public last: MicroPoint;
// Input
public inputEnabled: bool = false;
@@ -123,9 +142,6 @@ module Phaser {
}
private updateInput() {
}
private updateMotion() {
@@ -215,7 +231,7 @@ module Phaser {
/**
* Checks to see if this <code>GameObject</code> were located at the given position, would it overlap the <code>GameObject</code> or <code>Group</code>?
* This is distinct from overlapsPoint(), which just checks that ponumber, rather than taking the object's size numbero account.
* This is distinct from overlapsPoint(), which just checks that point, rather than taking the object's size numbero account.
* WARNING: Currently tilemaps do NOT support screen space overlap checks!
*
* @param X The X position you want to check. Pretends this object (the caller, not the parameter) is located here.
@@ -283,13 +299,13 @@ module Phaser {
}
/**
* Checks to see if a ponumber in 2D world space overlaps this <code>GameObject</code> object.
* Checks to see if a point in 2D world space overlaps this <code>GameObject</code>.
*
* @param Point The ponumber in world space you want to check.
* @param Point The point in world space you want to check.
* @param InScreenSpace Whether to take scroll factors numbero account when checking for overlap.
* @param Camera Specify which game camera you want. If null getScreenXY() will just grab the first global camera.
*
* @return Whether or not the ponumber overlaps this object.
* @return Whether or not the point overlaps this object.
*/
public overlapsPoint(point: Point, InScreenSpace: bool = false, Camera: Camera = null): bool {
@@ -315,7 +331,7 @@ module Phaser {
/**
* Check and see if this object is currently on screen.
*
* @param Camera Specify which game camera you want. If null getScreenXY() will just grab the first global camera.
* @param Camera Specify which game camera you want. If null getScreenXY() will just grab the first global camera.
*
* @return Whether the object is on screen or not.
*/
@@ -336,15 +352,15 @@ module Phaser {
* Call this to figure out the on-screen position of the object.
*
* @param Camera Specify which game camera you want. If null getScreenXY() will just grab the first global camera.
* @param Point Takes a <code>Point</code> object and assigns the post-scrolled X and Y values of this object to it.
* @param Point Takes a <code>MicroPoint</code> object and assigns the post-scrolled X and Y values of this object to it.
*
* @return The <code>Point</code> you passed in, or a new <code>Point</code> if you didn't pass one, containing the screen X and Y position of this object.
* @return The <code>MicroPoint</code> you passed in, or a new <code>Point</code> if you didn't pass one, containing the screen X and Y position of this object.
*/
public getScreenXY(point: Point = null, Camera: Camera = null): Point {
public getScreenXY(point: MicroPoint = null, Camera: Camera = null): MicroPoint {
if (point == null)
{
point = new Point();
point = new MicroPoint();
}
if (Camera == null)
@@ -387,21 +403,20 @@ module Phaser {
}
/**
* Retrieve the midponumber of this object in world coordinates.
* Retrieve the midpoint of this object in world coordinates.
*
* @Point Allows you to pass in an existing <code>Point</code> object if you're so inclined. Otherwise a new one is created.
*
* @return A <code>Point</code> object containing the midponumber of this object in world coordinates.
* @return A <code>Point</code> object containing the midpoint of this object in world coordinates.
*/
public getMidpoint(point: Point = null): Point {
public getMidpoint(point: MicroPoint = null): MicroPoint {
if (point == null)
{
point = new Point();
point = new MicroPoint();
}
point.x = this.x + this.width * 0.5;
point.y = this.y + this.height * 0.5;
point.copyFrom(this.bounds.center);
return point;
+25 -3
View File
@@ -182,7 +182,7 @@ module Phaser {
}
else
{
return camera.overlap(this.bounds);
return camera.intersects(this.bounds);
}
}
@@ -221,7 +221,8 @@ module Phaser {
this._dy -= (camera.worldView.y * this.scrollFactor.y);
}
// Rotation (could be misleading as it doesn't work re: collision)
// Rotation is disabled for now as I don't want it to be misleading re: collision
/*
if (this.angle !== 0)
{
this._game.stage.context.save();
@@ -230,6 +231,7 @@ module Phaser {
this._dx = -(this._dw / 2);
this._dy = -(this._dh / 2);
}
*/
this._dx = Math.round(this._dx);
this._dy = Math.round(this._dy);
@@ -286,7 +288,6 @@ module Phaser {
else
{
this._game.stage.context.beginPath();
this._game.stage.context.rect(this._dx, this._dy, this.rect.width, this.rect.height);
this._game.stage.context.stroke();
@@ -297,6 +298,19 @@ module Phaser {
this._game.stage.context.closePath();
}
// And now the edge points
this._game.stage.context.fillStyle = 'rgb(255,255,255)';
this.renderPoint(this._dx, this._dy, this.rect.topLeft, 2);
this.renderPoint(this._dx, this._dy, this.rect.topCenter, 2);
this.renderPoint(this._dx, this._dy, this.rect.topRight, 2);
this.renderPoint(this._dx, this._dy, this.rect.leftCenter, 2);
this.renderPoint(this._dx, this._dy, this.rect.center, 2);
this.renderPoint(this._dx, this._dy, this.rect.rightCenter, 2);
this.renderPoint(this._dx, this._dy, this.rect.bottomLeft, 2);
this.renderPoint(this._dx, this._dy, this.rect.bottomCenter, 2);
this.renderPoint(this._dx, this._dy, this.rect.bottomRight, 2);
}
this._game.stage.restoreCanvasValues();
@@ -316,6 +330,14 @@ module Phaser {
}
public renderPoint(offsetX, offsetY, point, size) {
offsetX = 0;
offsetY = 0;
this._game.stage.context.fillRect(offsetX + point.x, offsetY + point.y, 1, 1);
}
public renderDebugInfo(x: number, y: number, color?: string = 'rgb(255,255,255)') {
//this._game.stage.context.fillStyle = color;
+75 -12
View File
@@ -34,12 +34,8 @@ module Phaser {
}
private _texture;
private _canvas: HTMLCanvasElement;
private _context: CanvasRenderingContext2D;
private _dynamicTexture: bool = false;
public animations: AnimationManager;
// local rendering related temp vars to help avoid gc spikes
private _sx: number = 0;
private _sy: number = 0;
@@ -50,6 +46,12 @@ module Phaser {
private _dw: number = 0;
private _dh: number = 0;
public animations: AnimationManager;
public renderDebug: bool = false;
public renderDebugColor: string = 'rgba(0,255,0,0.5)';
public renderDebugPointColor: string = 'rgba(255,255,255,1)';
public loadGraphic(key: string): Sprite {
if (this._game.cache.getImage(key) !== null)
@@ -98,7 +100,7 @@ module Phaser {
}
public inCamera(camera: Rectangle): bool {
if (this.scrollFactor.x !== 1.0 || this.scrollFactor.y !== 1.0)
{
this._dx = this.bounds.x - (camera.x * this.scrollFactor.x);
@@ -110,7 +112,7 @@ module Phaser {
}
else
{
return camera.overlap(this.bounds);
return camera.intersects(this.bounds, this.bounds.length);
}
}
@@ -165,11 +167,48 @@ module Phaser {
this._sy = 0;
this._sw = this.bounds.width;
this._sh = this.bounds.height;
this._dx = cameraOffsetX + (this.bounds.x - camera.worldView.x);
this._dy = cameraOffsetY + (this.bounds.y - camera.worldView.y);
this._dx = cameraOffsetX + (this.bounds.topLeft.x - camera.worldView.x);
this._dy = cameraOffsetY + (this.bounds.topLeft.y - camera.worldView.y);
this._dw = this.bounds.width * this.scale.x;
this._dh = this.bounds.height * this.scale.y;
if (this.align == GameObject.ALIGN_TOP_CENTER)
{
this._dx -= this.bounds.halfWidth * this.scale.x;
}
else if (this.align == GameObject.ALIGN_TOP_RIGHT)
{
this._dx -= this.bounds.width * this.scale.x;
}
else if (this.align == GameObject.ALIGN_CENTER_LEFT)
{
this._dy -= this.bounds.halfHeight * this.scale.y;
}
else if (this.align == GameObject.ALIGN_CENTER)
{
this._dx -= this.bounds.halfWidth * this.scale.x;
this._dy -= this.bounds.halfHeight * this.scale.y;
}
else if (this.align == GameObject.ALIGN_CENTER_RIGHT)
{
this._dx -= this.bounds.width * this.scale.x;
this._dy -= this.bounds.halfHeight * this.scale.y;
}
else if (this.align == GameObject.ALIGN_BOTTOM_LEFT)
{
this._dy -= this.bounds.height * this.scale.y;
}
else if (this.align == GameObject.ALIGN_BOTTOM_CENTER)
{
this._dx -= this.bounds.halfWidth * this.scale.x;
this._dy -= this.bounds.height * this.scale.y;
}
else if (this.align == GameObject.ALIGN_BOTTOM_RIGHT)
{
this._dx -= this.bounds.width * this.scale.x;
this._dy -= this.bounds.height * this.scale.y;
}
if (this._dynamicTexture == false && this.animations.currentFrame !== null)
{
this._sx = this.animations.currentFrame.x;
@@ -209,10 +248,6 @@ module Phaser {
this._dw = Math.round(this._dw);
this._dh = Math.round(this._dh);
// Debug test
//this._game.stage.context.fillStyle = 'rgba(255,0,0,0.3)';
//this._game.stage.context.fillRect(this._dx, this._dy, this._dw, this._dh);
if (this._texture != null)
{
if (this._dynamicTexture)
@@ -250,6 +285,11 @@ module Phaser {
this._game.stage.context.fillRect(this._dx, this._dy, this._dw, this._dh);
}
if (this.renderDebug)
{
this.renderBounds();
}
//if (this.flip === true || this.rotation !== 0)
if (this.rotation !== 0)
{
@@ -266,6 +306,29 @@ module Phaser {
}
private renderBounds() {
this._game.stage.context.fillStyle = this.renderDebugColor;
this._game.stage.context.fillRect(this._dx, this._dy, this._dw, this._dh);
this._game.stage.context.fillStyle = this.renderDebugPointColor;
var hw = this.bounds.halfWidth * this.scale.x;
var hh = this.bounds.halfHeight * this.scale.y;
var sw = (this.bounds.width * this.scale.x) - 1;
var sh = (this.bounds.height * this.scale.y) - 1;
this._game.stage.context.fillRect(this._dx, this._dy, 1, 1); // top left
this._game.stage.context.fillRect(this._dx + hw, this._dy, 1, 1); // top center
this._game.stage.context.fillRect(this._dx + sw, this._dy, 1, 1); // top right
this._game.stage.context.fillRect(this._dx, this._dy + hh, 1, 1); // left center
this._game.stage.context.fillRect(this._dx + hw, this._dy + hh, 1, 1); // center
this._game.stage.context.fillRect(this._dx + sw, this._dy + hh, 1, 1); // right center
this._game.stage.context.fillRect(this._dx, this._dy + sh, 1, 1); // bottom left
this._game.stage.context.fillRect(this._dx + hw, this._dy + sh, 1, 1); // bottom center
this._game.stage.context.fillRect(this._dx + sw, this._dy + sh, 1, 1); // bottom right
}
public renderDebugInfo(x: number, y: number, color?: string = 'rgb(255,255,255)') {
this._game.stage.context.fillStyle = color;