Preparing new tests

This commit is contained in:
Richard Davey
2013-05-29 02:58:56 +01:00
parent 3c0c349089
commit 09f57fa346
237 changed files with 13385 additions and 34447 deletions
+7 -7
View File
@@ -1,4 +1,6 @@
/// <reference path="../Game.ts" />
/// <reference path="../utils/RectangleUtils.ts" />
/// <reference path="IGameObject.ts" />
/**
* Phaser - DynamicTexture
@@ -234,7 +236,7 @@ module Phaser {
public copyPixels(sourceTexture: DynamicTexture, sourceRect: Rectangle, destPoint: Point) {
// Swap for drawImage if the sourceRect is the same size as the sourceTexture to avoid a costly getImageData call
if (sourceRect.equals(this.bounds) == true)
if (Phaser.RectangleUtils.equals(sourceRect, this.bounds) == true)
{
this.context.drawImage(sourceTexture.canvas, destPoint.x, destPoint.y);
}
@@ -246,15 +248,15 @@ module Phaser {
}
/**
* Given an array of GameObjects it will update each of them so that their canvas/contexts reference this DynamicTexture
* Given an array of Sprites it will update each of them so that their canvas/contexts reference this DynamicTexture
* @param objects {Array} An array of GameObjects, or objects that inherit from it such as Sprites
*/
public assignCanvasToGameObjects(objects: GameObject[]) {
public assignCanvasToGameObjects(objects: IGameObject[]) {
for (var i = 0; i < objects.length; i++)
{
objects[i].canvas = this.canvas;
objects[i].context = this.context;
objects[i].texture.canvas = this.canvas;
objects[i].texture.context = this.context;
}
}
@@ -275,9 +277,7 @@ module Phaser {
* @param y {number} The Y coordinate to render on the stage to (given in screen coordinates, not world)
*/
public render(x?: number = 0, y?: number = 0) {
this.game.stage.context.drawImage(this.canvas, x, y);
}
public get width(): number {
+6 -6
View File
@@ -135,9 +135,9 @@ module Phaser {
* @param [tileHeight] {number} height of each tile.
* @return {Tilemap} The newly created tilemap object.
*/
public tilemap(key: string, mapData: string, format: number, resizeWorld: bool = true, tileWidth?: number = 0, tileHeight?: number = 0): Tilemap {
return <Tilemap> this._world.group.add(new Tilemap(this._game, key, mapData, format, resizeWorld, tileWidth, tileHeight));
}
//public tilemap(key: string, mapData: string, format: number, resizeWorld: bool = true, tileWidth?: number = 0, tileHeight?: number = 0): Tilemap {
// return <Tilemap> this._world.group.add(new Tilemap(this._game, key, mapData, format, resizeWorld, tileWidth, tileHeight));
//}
/**
* Create a tween object for a specific object.
@@ -200,9 +200,9 @@ module Phaser {
* @param tilemap The Tilemap to add to the Game World
* @return {Phaser.Tilemap} The Tilemap object
*/
public existingTilemap(tilemap: Tilemap): Tilemap {
return this._world.group.add(tilemap);
}
//public existingTilemap(tilemap: Tilemap): Tilemap {
// return this._world.group.add(tilemap);
//}
/**
* Add an existing Tween to the current world.
+59
View File
@@ -0,0 +1,59 @@
/// <reference path="../Game.ts" />
module Phaser {
export interface IGameObject {
/**
* Reference to the main game object
*/
game: Game;
/**
* The type of game object.
*/
type: number;
/**
* Reference to the Renderer.renderSprite method. Can be overriden by custom classes.
*/
render;
/**
* Controls if both <code>update</code> and render are called by the core game loop.
*/
exists: bool;
/**
* Controls if <code>update()</code> is automatically called by the core game loop.
*/
active: bool;
/**
* Controls if this Sprite is rendered or skipped during the core game loop.
*/
visible: bool;
/**
* The position of the Sprite in world and screen coordinates.
*/
position: Phaser.Components.Position;
/**
* The texture used to render the Sprite.
*/
texture: Phaser.Components.Texture;
/**
* Scale of the Sprite. A scale of 1.0 is the original size. 0.5 half size. 2.0 double sized.
*/
scale: Phaser.Vec2;
/**
* The influence of camera movement upon the Sprite.
*/
scrollFactor: Phaser.Vec2;
}
}
+115 -1
View File
@@ -11,7 +11,7 @@
module Phaser {
export class Sprite {
export class Sprite implements IGameObject {
/**
* Create a new <code>Sprite</code>.
@@ -34,12 +34,18 @@ module Phaser {
this.visible = true;
this.alive = true;
this.frameBounds = new Rectangle(x, y, width, height);
this.origin = new Phaser.Vec2(0, 0);
this.scrollFactor = new Phaser.Vec2(1, 1);
this.scale = new Phaser.Vec2(1, 1);
this.position = new Phaser.Components.Position(this, x, y);
this.texture = new Phaser.Components.Texture(this, key, game.stage.canvas, game.stage.context);
this.width = this.frameBounds.width;
this.height = this.frameBounds.height;
this.rotation = this.position.rotation;
}
/**
@@ -77,6 +83,10 @@ module Phaser {
*/
public alive: bool;
// Getters only, don't over-write these values
public width: number;
public height: number;
/**
* The position of the Sprite in world and screen coordinates.
*/
@@ -94,9 +104,102 @@ module Phaser {
*/
public frameBounds: Phaser.Rectangle;
/**
* Scale of the Sprite. A scale of 1.0 is the original size. 0.5 half size. 2.0 double sized.
*/
public scale: Phaser.Vec2;
/**
* The influence of camera movement upon the Sprite.
*/
public scrollFactor: Phaser.Vec2;
/**
* The Sprite origin is the point around which scale and rotation transforms take place.
*/
public origin: Phaser.Vec2;
/**
* Pre-update is called right before update() on each object in the game loop.
*/
public preUpdate() {
//this.last.x = this.frameBounds.x;
//this.last.y = this.frameBounds.y;
//this.collisionMask.preUpdate();
}
/**
* Override this function to update your class's position and appearance.
*/
public update() {
}
/**
* Automatically called after update() by the game loop.
*/
public postUpdate() {
/*
this.animations.update();
if (this.moves)
{
this.updateMotion();
}
if (this.worldBounds != null)
{
if (this.outOfBoundsAction == GameObject.OUT_OF_BOUNDS_KILL)
{
if (this.x < this.worldBounds.x || this.x > this.worldBounds.right || this.y < this.worldBounds.y || this.y > this.worldBounds.bottom)
{
this.kill();
}
}
else
{
if (this.x < this.worldBounds.x)
{
this.x = this.worldBounds.x;
}
else if (this.x > this.worldBounds.right)
{
this.x = this.worldBounds.right;
}
if (this.y < this.worldBounds.y)
{
this.y = this.worldBounds.y;
}
else if (this.y > this.worldBounds.bottom)
{
this.y = this.worldBounds.bottom;
}
}
}
this.collisionMask.update();
if (this.inputEnabled)
{
this.updateInput();
}
this.wasTouching = this.touching;
this.touching = Collision.NONE;
*/
}
/**
* Clean up memory.
*/
public destroy() {
}
/**
* x value of the object.
*/
@@ -130,6 +233,17 @@ module Phaser {
this.position.z = value;
}
/**
* rotation value of the object.
*/
public get rotation(): number {
return this.position.rotation;
}
public set rotation(value: number) {
this.position.rotation = value;
}
}
}