Skip to content

Commit bd54460

Browse files
committed
Added the GameObjectManager
1 parent e2141c9 commit bd54460

54 files changed

Lines changed: 9667 additions & 2810 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Phaser/AnimationManager.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,15 @@ module Phaser {
211211
}
212212

213213
public get frameTotal(): number {
214-
return this._frameData.total;
214+
215+
if (this._frameData)
216+
{
217+
return this._frameData.total;
218+
}
219+
else
220+
{
221+
return -1;
222+
}
215223
}
216224

217225
public get frame(): number {
@@ -248,6 +256,19 @@ module Phaser {
248256

249257
}
250258

259+
/**
260+
* Removes all related references
261+
*/
262+
public destroy() {
263+
264+
this._anims = {};
265+
this._frameData = null;
266+
this._frameIndex = 0;
267+
this.currentAnim = null;
268+
this.currentFrame = null;
269+
270+
}
271+
251272
}
252273

253274
}

Phaser/CameraManager.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
*
77
* Your game only has one CameraManager instance and it's responsible for looking after, creating and destroying
88
* all of the cameras in the world.
9-
*
10-
* TODO: If the Camera is larger than the Stage size then the rotation offset isn't correct
11-
* TODO: Texture Repeat doesn't scroll, because it's part of the camera not the world, need to think about this more
129
*/
1310

1411
module Phaser {

Phaser/Collision.ts

Lines changed: 573 additions & 155 deletions
Large diffs are not rendered by default.

Phaser/Game.ts

Lines changed: 9 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
/// <reference path="DynamicTexture.ts" />
77
/// <reference path="FXManager.ts" />
88
/// <reference path="GameMath.ts" />
9+
/// <reference path="GameObjectFactory.ts" />
910
/// <reference path="Group.ts" />
1011
/// <reference path="Loader.ts" />
1112
/// <reference path="Motion.ts" />
@@ -172,6 +173,12 @@ module Phaser {
172173
*/
173174
public onDestroyCallback = null;
174175

176+
/**
177+
* Reference to the GameObject Factory.
178+
* @type {GameObjectFactory}
179+
*/
180+
public add: GameObjectFactory;
181+
175182
/**
176183
* Reference to the assets cache.
177184
* @type {Cache}
@@ -251,7 +258,7 @@ module Phaser {
251258
public rnd: RandomDataGenerator;
252259

253260
/**
254-
* Device detector.
261+
* Contains device information and capabilities.
255262
* @type {Device}
256263
*/
257264
public device: Device;
@@ -292,6 +299,7 @@ module Phaser {
292299
this.math = new GameMath(this);
293300
this.stage = new Stage(this, parent, width, height);
294301
this.world = new World(this, width, height);
302+
this.add = new GameObjectFactory(this);
295303
this.sound = new SoundManager(this);
296304
this.cache = new Cache(this);
297305
this.collision = new Collision(this);
@@ -619,125 +627,6 @@ module Phaser {
619627

620628
}
621629

622-
// Handy Proxy methods
623-
624-
/**
625-
* Create a new camera with specific position and size.
626-
*
627-
* @param x {number} X position of the new camera.
628-
* @param y {number} Y position of the new camera.
629-
* @param width {number} Width of the new camera.
630-
* @param height {number} Height of the new camera.
631-
* @returns {Camera} The newly created camera object.
632-
*/
633-
public createCamera(x: number, y: number, width: number, height: number): Camera {
634-
return this.world.createCamera(x, y, width, height);
635-
}
636-
637-
/**
638-
* Create a new GeomSprite with specific position.
639-
*
640-
* @param x {number} X position of the new geom sprite.
641-
* @param y {number} Y position of the new geom sprite.
642-
* @returns {GeomSprite} The newly created geom sprite object.
643-
*/
644-
public createGeomSprite(x: number, y: number): GeomSprite {
645-
return this.world.createGeomSprite(x, y);
646-
}
647-
648-
/**
649-
* Create a new Sprite with specific position and sprite sheet key.
650-
*
651-
* @param x {number} X position of the new sprite.
652-
* @param y {number} Y position of the new sprite.
653-
* @param key {string} Optional, key for the sprite sheet you want it to use.
654-
* @returns {Sprite} The newly created sprite object.
655-
*/
656-
public createSprite(x: number, y: number, key?: string = ''): Sprite {
657-
return this.world.createSprite(x, y, key);
658-
}
659-
660-
/**
661-
* Create a new DynamicTexture with specific size.
662-
*
663-
* @param width {number} Width of the texture.
664-
* @param height {number} Height of the texture.
665-
* @returns {DynamicTexture} The newly created dynamic texture object.
666-
*/
667-
public createDynamicTexture(width: number, height: number): DynamicTexture {
668-
return this.world.createDynamicTexture(width, height);
669-
}
670-
671-
/**
672-
* Create a new object container.
673-
*
674-
* @param maxSize {number} Optional, capacity of this group.
675-
* @returns {Group} The newly created group.
676-
*/
677-
public createGroup(maxSize?: number = 0): Group {
678-
return this.world.createGroup(maxSize);
679-
}
680-
681-
/**
682-
* Create a new Particle.
683-
*
684-
* @return {Particle} The newly created particle object.
685-
*/
686-
public createParticle(): Particle {
687-
return this.world.createParticle();
688-
}
689-
690-
/**
691-
* Create a new Emitter.
692-
*
693-
* @param x {number} Optional, x position of the emitter.
694-
* @param y {number} Optional, y position of the emitter.
695-
* @param size {number} Optional, size of this emitter.
696-
* @return {Emitter} The newly created emitter object.
697-
*/
698-
public createEmitter(x?: number = 0, y?: number = 0, size?: number = 0): Emitter {
699-
return this.world.createEmitter(x, y, size);
700-
}
701-
702-
/**
703-
* Create a new ScrollZone object with image key, position and size.
704-
*
705-
* @param key {string} Key to a image you wish this object to use.
706-
* @param x {number} X position of this object.
707-
* @param y {number} Y position of this object.
708-
* @param width number} Width of this object.
709-
* @param height {number} Height of this object.
710-
* @returns {ScrollZone} The newly created scroll zone object.
711-
*/
712-
public createScrollZone(key: string, x?: number = 0, y?: number = 0, width?: number = 0, height?: number = 0): ScrollZone {
713-
return this.world.createScrollZone(key, x, y, width, height);
714-
}
715-
716-
/**
717-
* Create a new Tilemap.
718-
*
719-
* @param key {string} Key for tileset image.
720-
* @param mapData {string} Data of this tilemap.
721-
* @param format {number} Format of map data. (Tilemap.FORMAT_CSV or Tilemap.FORMAT_TILED_JSON)
722-
* @param [resizeWorld] {boolean} resize the world to make same as tilemap?
723-
* @param [tileWidth] {number} width of each tile.
724-
* @param [tileHeight] {number} height of each tile.
725-
* @return {Tilemap} The newly created tilemap object.
726-
*/
727-
public createTilemap(key: string, mapData: string, format: number, resizeWorld: bool = true, tileWidth?: number = 0, tileHeight?: number = 0): Tilemap {
728-
return this.world.createTilemap(key, mapData, format, resizeWorld, tileWidth, tileHeight);
729-
}
730-
731-
/**
732-
* Create a tween object for a specific object.
733-
*
734-
* @param obj Object you wish the tween will affect.
735-
* @return {Phaser.Tween} The newly created tween object.
736-
*/
737-
public createTween(obj): Tween {
738-
return this.tweens.create(obj);
739-
}
740-
741630
/**
742631
* Checks for overlaps between two objects using the world QuadTree. Can be GameObject vs. GameObject, GameObject vs. Group or Group vs. Group.
743632
* Note: Does not take the objects scrollFactor into account. All overlaps are check in world space.

Phaser/GameMath.ts

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,25 +1039,32 @@ module Phaser {
10391039
}
10401040

10411041
/**
1042-
* Rotates a point around the x/y coordinates given to the desired angle
1042+
* Rotates the point around the x/y coordinates given to the desired angle and distance
1043+
* @param point {Object} Any object with exposed x and y properties
10431044
* @param x {number} The x coordinate of the anchor point
10441045
* @param y {number} The y coordinate of the anchor point
1045-
* @param angle {number} The angle of the rotation in radians
1046-
* @param point {Point} The point object to perform the rotation on
1046+
* @param {Number} angle The angle in radians (unless asDegrees is true) to return the point from.
1047+
* @param {Boolean} asDegrees Is the given angle in radians (false) or degrees (true)?
1048+
* @param {Number} distance An optional distance constraint between the point and the anchor
10471049
* @return The modified point object
10481050
*/
1049-
public rotatePoint(x: number, y: number, angle: number, point) {
1051+
public rotatePoint(point, x1: number, y1: number, angle: number, asDegrees: bool = false, distance?:number = null) {
10501052

1051-
var s: number = Math.sin(angle);
1052-
var c: number = Math.cos(angle);
1053+
if (asDegrees)
1054+
{
1055+
angle = angle * GameMath.DEG_TO_RAD;
1056+
}
10531057

1054-
point.x -= x;
1055-
point.y -= y;
1058+
// Get distance from origin to the point
1059+
if (distance === null)
1060+
{
1061+
distance = Math.sqrt(((x1 - point.x) * (x1 - point.x)) + ((y1 - point.y) * (y1 - point.y)));
1062+
}
10561063

1057-
var newX: number = point.x * c - point.y * s;
1058-
var newY: number = point.x * s - point.y * c;
1064+
point.x = x1 + distance * Math.cos(angle);
1065+
point.y = y1 + distance * Math.sin(angle);
10591066

1060-
return point.setTo(newX + x, newY + y);
1067+
return point;
10611068

10621069
}
10631070

0 commit comments

Comments
 (0)