Added the GameObjectManager

This commit is contained in:
Richard Davey
2013-05-23 00:01:58 +01:00
parent e2141c91a6
commit bd54460e80
54 changed files with 9378 additions and 2521 deletions
+6
View File
@@ -835,6 +835,12 @@ module Phaser {
* Clean up memory.
*/
public destroy() {
}
public setPosition(x: number, y: number) {
this.x = x;
this.y = y;
}
+29
View File
@@ -1,4 +1,5 @@
/// <reference path="../Game.ts" />
/// <reference path="../geom/Polygon.ts" />
/**
* Phaser - GeomSprite
@@ -71,6 +72,12 @@ module Phaser {
*/
public static RECTANGLE: number = 4;
/**
* Polygon.
* @type {number}
*/
public static POLYGON: number = 5;
/**
* Circle shape container. A Circle instance.
* @type {Circle}
@@ -95,6 +102,12 @@ module Phaser {
*/
public rect: Rectangle;
/**
* Polygon shape container. A Polygon instance.
* @type {Polygon}
*/
public polygon: Polygon;
/**
* Render outline of this sprite or not. (default is true)
* @type {boolean}
@@ -243,6 +256,22 @@ module Phaser {
}
/**
* Create a polygon object
* @param width {Number} Width of the rectangle
* @param height {Number} Height of the rectangle
* @return {GeomSprite} GeomSprite instance.
*/
createPolygon(points?: Vector2[] = []): GeomSprite {
this.refresh();
this.polygon = new Polygon(new Vector2(this.x, this.y), points);
this.type = GeomSprite.POLYGON;
//this.frameBounds.copyFrom(this.rect);
return this;
}
/**
* Destroy all geom shapes of this sprite.
*/
+30 -15
View File
@@ -109,9 +109,15 @@ module Phaser {
/**
* Load graphic for this sprite. (graphic can be SpriteSheet or Texture)
* @param key {string} Key of the graphic you want to load for this sprite.
* @param clearAnimations {boolean} If this Sprite has a set of animation data already loaded you can choose to keep or clear it with this boolean
* @return {Sprite} Sprite instance itself.
*/
public loadGraphic(key: string): Sprite {
public loadGraphic(key: string, clearAnimations: bool = true): Sprite {
if (clearAnimations && this.animations.frameData !== null)
{
this.animations.destroy();
}
if (this._game.cache.getImage(key) !== null)
{
@@ -127,8 +133,8 @@ module Phaser {
{
this._texture = this._game.cache.getImage(key);
this.animations.loadFrameData(this._game.cache.getFrameData(key));
//this.collisionMask.width = this._texture.width;
//this.collisionMask.height = this._texture.height;
this.collisionMask.width = this.animations.currentFrame.width;
this.collisionMask.height = this.animations.currentFrame.height;
}
this._dynamicTexture = false;
@@ -181,19 +187,27 @@ module Phaser {
*/
public inCamera(camera: Rectangle): bool {
if (this.scrollFactor.x !== 1.0 || this.scrollFactor.y !== 1.0)
// Object fixed in place regardless of the camera scrolling? Then it's always visible
if (this.scrollFactor.x == 0 && this.scrollFactor.y == 0)
{
this._dx = this.frameBounds.x - (camera.x * this.scrollFactor.x);
this._dy = this.frameBounds.y - (camera.y * this.scrollFactor.x);
return true;
}
// Otherwise, if it's scrolling perfectly in sync with the camera (1 to 1) then it's a simple bounds check on world coordinates
if (this.scrollFactor.x == 1 && this.scrollFactor.y == 1)
{
return camera.intersects(this.frameBounds, this.frameBounds.length);
}
else
{
// Else apply the offsets
this._dx = (this.frameBounds.x - camera.x) * this.scrollFactor.x;
this._dy = (this.frameBounds.y - camera.y) * this.scrollFactor.y;
this._dw = this.frameBounds.width * this.scale.x;
this._dh = this.frameBounds.height * this.scale.y;
return (camera.right > this._dx) && (camera.x < this._dx + this._dw) && (camera.bottom > this._dy) && (camera.y < this._dy + this._dh);
}
else
{
return camera.intersects(this.frameBounds, this.frameBounds.length);
}
}
@@ -250,8 +264,9 @@ module Phaser {
this._sy = 0;
this._sw = this.frameBounds.width;
this._sh = this.frameBounds.height;
this._dx = cameraOffsetX + (this.frameBounds.topLeft.x - camera.worldView.x);
this._dy = cameraOffsetY + (this.frameBounds.topLeft.y - camera.worldView.y);
this._dx = (cameraOffsetX * this.scrollFactor.x) + this.frameBounds.topLeft.x - (camera.worldView.x * this.scrollFactor.x);
this._dy = (cameraOffsetY * this.scrollFactor.y) + this.frameBounds.topLeft.y - (camera.worldView.y * this.scrollFactor.y);
this._dw = this.frameBounds.width * this.scale.x;
this._dh = this.frameBounds.height * this.scale.y;
@@ -305,10 +320,10 @@ module Phaser {
}
// Apply camera difference
if (this.scrollFactor.x !== 1.0 || this.scrollFactor.y !== 1.0)
if (this.scrollFactor.x !== 1 || this.scrollFactor.y !== 1)
{
this._dx -= (camera.worldView.x * this.scrollFactor.x);
this._dy -= (camera.worldView.y * this.scrollFactor.y);
//this._dx -= (camera.worldView.x * this.scrollFactor.x);
//this._dy -= (camera.worldView.y * this.scrollFactor.y);
}
// Rotation - needs to work from origin point really, but for now from center