Finish document for Cache, Game, Stage, State and World class.

This commit is contained in:
Sean
2013-05-10 16:31:12 +01:00
committed by Richard Davey
parent b1a33cc593
commit 98693cb418
5 changed files with 743 additions and 3 deletions
+106
View File
@@ -11,6 +11,9 @@ module Phaser {
export class Cache {
/**
* Cache constructor
*/
constructor(game: Game) {
this._game = game;
@@ -22,19 +25,53 @@ module Phaser {
}
/**
* Local private reference to game.
*/
private _game: Game;
/**
* Canvas key-value container.
* @type {object}
*/
private _canvases;
/**
* Image key-value container.
* @type {object}
*/
private _images;
/**
* Sound key-value container.
* @type {object}
*/
private _sounds;
/**
* Text key-value container.
* @type {object}
*/
private _text;
/**
* Add a new canvas.
* @param key Asset key for this canvas.
* @param canvas Canvas DOM element.
* @param context Render context of this canvas.
*/
public addCanvas(key: string, canvas: HTMLCanvasElement, context: CanvasRenderingContext2D) {
this._canvases[key] = { canvas: canvas, context: context };
}
/**
* Add a new sprite sheet.
* @param key Asset key for the sprite sheet.
* @param url URL of this sprite sheet file.
* @param data Extra sprite sheet data.
* @param frameWidth Width of the sprite sheet.
* @param frameHeight Height of the sprite sheet.
* @param frameMax How many frames stored in the sprite sheet.
*/
public addSpriteSheet(key: string, url: string, data, frameWidth: number, frameHeight: number, frameMax: number) {
this._images[key] = { url: url, data: data, spriteSheet: true, frameWidth: frameWidth, frameHeight: frameHeight };
@@ -42,6 +79,13 @@ module Phaser {
}
/**
* Add a new texture atlas.
* @param key Asset key for the texture atlas.
* @param url URL of this texture atlas file.
* @param data Extra texture atlas data.
* @param data Texture atlas frames data.
*/
public addTextureAtlas(key: string, url: string, data, jsonData) {
this._images[key] = { url: url, data: data, spriteSheet: true };
@@ -49,18 +93,36 @@ module Phaser {
}
/**
* Add a new image.
* @param key Asset key for the image.
* @param url URL of this image file.
* @param data Extra image data.
*/
public addImage(key: string, url: string, data) {
this._images[key] = { url: url, data: data, spriteSheet: false };
}
/**
* Add a new sound.
* @param key Asset key for the sound.
* @param url URL of this sound file.
* @param data Extra sound data.
*/
public addSound(key: string, url: string, data) {
this._sounds[key] = { url: url, data: data, decoded: false };
}
/**
* Add a new decoded sound.
* @param key Asset key for the sound.
* @param url URL of this sound file.
* @param data Extra sound data.
*/
public decodedSound(key: string, data) {
this._sounds[key].data = data;
@@ -68,12 +130,23 @@ module Phaser {
}
/**
* Add a new text data.
* @param key Asset key for the text data.
* @param url URL of this text data file.
* @param data Extra text data.
*/
public addText(key: string, url: string, data) {
this._text[key] = { url: url, data: data };
}
/**
* Get canvas by key.
* @param key Asset key of the canvas you want.
* @return {object} The canvas you want.
*/
public getCanvas(key: string) {
if (this._canvases[key])
@@ -85,6 +158,11 @@ module Phaser {
}
/**
* Get image data by key.
* @param key Asset key of the image you want.
* @return {object} The image data you want.
*/
public getImage(key: string) {
if (this._images[key])
@@ -96,6 +174,11 @@ module Phaser {
}
/**
* Get frame data by key.
* @param key Asset key of the frame data you want.
* @return {object} The frame data you want.
*/
public getFrameData(key: string): FrameData {
if (this._images[key] && this._images[key].spriteSheet == true)
@@ -107,6 +190,11 @@ module Phaser {
}
/**
* Get sound data by key.
* @param key Asset key of the sound you want.
* @return {object} The sound data you want.
*/
public getSound(key: string) {
if (this._sounds[key])
@@ -118,6 +206,11 @@ module Phaser {
}
/**
* Check whether an asset is decoded sound.
* @param key Asset key of the sound you want.
* @return {object} The sound data you want.
*/
public isSoundDecoded(key: string): bool {
if (this._sounds[key])
@@ -127,6 +220,11 @@ module Phaser {
}
/**
* Check whether an asset is sprite sheet.
* @param key Asset key of the sprite sheet you want.
* @return {object} The sprite sheet data you want.
*/
public isSpriteSheet(key: string): bool {
if (this._images[key])
@@ -136,6 +234,11 @@ module Phaser {
}
/**
* Get text data by key.
* @param key Asset key of the text data you want.
* @return {object} The text data you want.
*/
public getText(key: string) {
if (this._text[key])
@@ -147,6 +250,9 @@ module Phaser {
}
/**
* Clean up cache memory.
*/
public destroy() {
for (var item in this._canvases)
+243 -3
View File
@@ -34,7 +34,7 @@
/**
* Phaser - Game
*
* This is where the magic happens. The Game object is the heart of your game,
* This is where the magic happens. The Game object is the heart of your game,
* providing quick access to common functions and handling the boot process.
*
* "Hell, there are no rules here - we're trying to accomplish something."
@@ -45,6 +45,20 @@ module Phaser {
export class Game {
/**
* Game constructor
*
* Instantiate a new <code>Game</code> object.
*
* @param callbackContext Which context will the callbacks be called with.
* @param parent ID of its parent DOM element.
* @param width The width of your game in game pixels.
* @param height The height of your game in game pixels.
* @param initCallback Init callback invoked when init default screen.
* @param createCallback Create callback invoked when create default screen.
* @param updateCallback Update callback invoked when update default screen.
* @param renderCallback Render callback invoked when render default screen.
*/
constructor(callbackContext, parent?: string = '', width?: number = 800, height?: number = 600, initCallback = null, createCallback = null, updateCallback = null, renderCallback = null) {
this.callbackContext = callbackContext;
@@ -65,39 +79,155 @@ module Phaser {
}
/**
* Game loop trigger wrapper.
*/
private _raf: RequestAnimationFrame;
/**
* Max allowable accumulation.
* @type {number}
*/
private _maxAccumulation: number = 32;
/**
* Total number of milliseconds elapsed since last update loop.
* @type {number}
*/
private _accumulator: number = 0;
/**
* Milliseconds of time per step of the game loop.
* @type {number}
*/
private _step: number = 0;
/**
* Whether loader complete loading or not.
* @type {boolean}
*/
private _loadComplete: bool = false;
/**
* Game is paused?
* @type {boolean}
*/
private _paused: bool = false;
/**
* The state to be switched to in the next frame.
* @type {State}
*/
private _pendingState = null;
// Event callbacks
/**
* Context for calling the callbacks.
*/
public callbackContext;
/**
* This will be called when init states. (loading assets...)
* @type {function}
*/
public onInitCallback = null;
/**
* This will be called when create states. (setup states...)
* @type {function}
*/
public onCreateCallback = null;
/**
* This will be called when update states.
* @type {function}
*/
public onUpdateCallback = null;
/**
* This will be called when render states.
* @type {function}
*/
public onRenderCallback = null;
/**
* This will be called when states paused.
* @type {function}
*/
public onPausedCallback = null;
/**
* Reference to the assets cache.
* @type {Cache}
*/
public cache: Cache;
/**
* Reference to the collision helper.
* @type {Collision}
*/
public collision: Collision;
/**
* Reference to the input manager
* @type {Input}
*/
public input: Input;
/**
* Reference to the assets loader.
* @type {Loader}
*/
public loader: Loader;
/**
* Reference to the math helper.
* @type {GameMath}
*/
public math: GameMath;
/**
* Reference to the motion helper.
* @type {Motion}
*/
public motion: Motion;
/**
* Reference to the sound manager.
* @type {SoundManager}
*/
public sound: SoundManager;
/**
* Reference to the stage.
* @type {Stage}
*/
public stage: Stage;
/**
* Reference to game clock.
* @type {Time}
*/
public time: Time;
/**
* Reference to the tween manager.
* @type {TweenManager}
*/
public tweens: TweenManager;
/**
* Reference to the world.
* @type {World}
*/
public world: World;
/**
* Instance of repeatable random data generator helper.
* @type {RandomDataGenerator}
*/
public rnd: RandomDataGenerator;
/**
* Device detector.
* @type {Device}
*/
public device: Device;
/**
* Whether the game engine is booted, aka available.
* @type {boolean}
*/
public isBooted: bool = false;
/**
* Is game running or paused?
* @type {boolean}
*/
public isRunning: bool = false;
/**
* Initialize engine sub modules and start the game.
* @param parent ID of parent Dom element.
* @param width Width of the game screen.
* @param height Height of the game screen.
*/
private boot(parent: string, width: number, height: number) {
if (this.isBooted == true)
@@ -155,13 +285,18 @@ module Phaser {
}
/**
* Called when the loader has finished after init was run.
*/
private loadComplete() {
// Called when the loader has finished after init was run
this._loadComplete = true;
}
/**
* Game loop method will be called when it's booting.
*/
private bootLoop() {
this.time.update();
@@ -171,6 +306,9 @@ module Phaser {
}
/**
* Game loop method will be called when it's paused.
*/
private pausedLoop() {
this.time.update();
@@ -185,6 +323,9 @@ module Phaser {
}
/**
* Game loop method will be called when it's running.
*/
private loop() {
this.time.update();
@@ -220,6 +361,9 @@ module Phaser {
}
/**
* Start current state.
*/
private startState() {
if (this.onInitCallback !== null)
@@ -252,6 +396,13 @@ module Phaser {
}
/**
* Set all state callbacks (init, create, update, render).
* @param initCallback Init callback invoked when init state.
* @param createCallback Create callback invoked when create state.
* @param updateCallback Update callback invoked when update state.
* @param renderCallback Render callback invoked when render state.
*/
public setCallbacks(initCallback = null, createCallback = null, updateCallback = null, renderCallback = null) {
this.onInitCallback = initCallback;
@@ -261,6 +412,12 @@ module Phaser {
}
/**
* Switch to a new State.
* @param state The state you want to switch to.
* @param clearWorld Optional, clear everything in the world? (Default to true)
* @param clearCache Optional, clear asset cache? (Default to false and ONLY available when clearWorld=true)
*/
public switchState(state, clearWorld: bool = true, clearCache: bool = false) {
if (this.isBooted == false)
@@ -333,7 +490,9 @@ module Phaser {
}
// Nuke the whole game from orbit
/**
* Nuke the whole game from orbit
*/
public destroy() {
this.callbackContext = null;
@@ -398,46 +557,127 @@ module Phaser {
// Handy Proxy methods
/**
* Create a new camera with specific position and size.
*
* @param x X position of the new camera.
* @param y Y position of the new camera.
* @param width Width of the new camera.
* @param height Height of the new camera.
* @returns {Camera=} The newly created camera object.
*/
public createCamera(x: number, y: number, width: number, height: number): Camera {
return this.world.createCamera(x, y, width, height);
}
/**
* Create a new GeomSprite with specific position.
*
* @param x X position of the new geom sprite.
* @param y Y position of the new geom sprite.
* @returns {GeomSprite=} The newly created geom sprite object.
*/
public createGeomSprite(x: number, y: number): GeomSprite {
return this.world.createGeomSprite(x, y);
}
/**
* Create a new Sprite with specific position and sprite sheet key.
*
* @param x X position of the new sprite.
* @param y Y position of the new sprite.
* @param key Optinal, key for the sprite sheet you want it to use.
* @returns {Sprite=} The newly created sprite object.
*/
public createSprite(x: number, y: number, key?: string = ''): Sprite {
return this.world.createSprite(x, y, key);
}
/**
* Create a new DynamicTexture with specific size.
*
* @param width Width of the texture.
* @param height Height of the texture.
* @returns {DynamicTexture=} The newly created dynamic texture object.
*/
public createDynamicTexture(width: number, height: number): DynamicTexture {
return this.world.createDynamicTexture(width, height);
}
/**
* Create a new object container.
*
* @param MaxSize Optinal, capacity of this group.
* @returns {Group=} The newly created group.
*/
public createGroup(MaxSize?: number = 0): Group {
return this.world.createGroup(MaxSize);
}
/**
* Create a new Particle.
*
* @return {Particle=} The newly created particle object.
*/
public createParticle(): Particle {
return this.world.createParticle();
}
/**
* Create a new Emitter.
*
* @param x Optinal, x position of the emitter.
* @param y Optinal, y position of the emitter.
* @param size Optinal, size of this emitter.
* @return {Emitter=} The newly created emitter object.
*/
public createEmitter(x?: number = 0, y?: number = 0, size?: number = 0): Emitter {
return this.world.createEmitter(x, y, size);
}
/**
* Create a new ScrollZone object with image key, position and size.
*
* @param key Key to a image you wish this object to use.
* @param x X position of this object.
* @param y Y position of this object.
* @param width Width of this object.
* @param height Heigth of this object.
* @returns {ScrollZone=} The newly created scroll zone object.
*/
public createScrollZone(key: string, x?: number = 0, y?: number = 0, width?: number = 0, height?: number = 0): ScrollZone {
return this.world.createScrollZone(key, x, y, width, height);
}
/**
* Create a new Tilemap.
*
* @param key Key for tileset image.
* @param mapData Data of this tilemap.
* @param format Format of map data. (Tilemap.FORMAT_CSV or Tilemap.FORMAT_TILED_JSON)
* @param resizeWorld Optinal, resize the world to make same as tilemap?
* @param tileWidth Optinal, width of each tile.
* @param tileHeight Optinal, height of each tile.
* @return {Tilemap=} The newly created tilemap object.
*/
public createTilemap(key: string, mapData: string, format: number, resizeWorld: bool = true, tileWidth?: number = 0, tileHeight?: number = 0): Tilemap {
return this.world.createTilemap(key, mapData, format, resizeWorld, tileWidth, tileHeight);
}
/**
* Create a tween object for a specific object.
*
* @param obj Object you wish the tween will affect.
* @return {Phaser.Tween=} The newly created tween object.
*/
public createTween(obj): Tween {
return this.tweens.create(obj);
}
/**
* Call this method to see if one object collids another.
* @return {boolean} Whether the given objects or groups collids.
*/
public collide(objectOrGroup1: Basic = null, objectOrGroup2: Basic = null, notifyCallback = null): bool {
return this.collision.overlap(objectOrGroup1, objectOrGroup2, notifyCallback, Collision.separate);
}
+116
View File
@@ -15,6 +15,15 @@ module Phaser {
export class Stage {
/**
* Stage constructor
*
* Create a new <code>Stage</code> with specific width and height.
*
* @param parent ID of parent DOM element.
* @param width Width of the stage.
* @param height Height of the stage.
*/
constructor(game: Game, parent: string, width: number, height: number) {
this._game = game;
@@ -55,30 +64,116 @@ module Phaser {
}
/**
* Local private reference to game.
*/
private _game: Game;
/**
* Background color of the stage.
* @type {string}
*/
private _bgColor: string;
/**
* This will be displayed when Phaser is started without any default functions or State
* @type {BootScreen}
*/
private _bootScreen;
/**
* This will be displayed whenever the game loses focus or the player switches to another browser tab.
* @type {PauseScreen}
*/
private _pauseScreen;
/**
* Screen orientation enum: Landscape.
* @type {number}
*/
public static ORIENTATION_LANDSCAPE: number = 0;
/**
* Screen orientation enum: Portrait.
* @type {number}
*/
public static ORIENTATION_PORTRAIT: number = 1;
/**
* Bound of this stage.
* @type {Rectangle}
*/
public bounds: Rectangle;
/**
* Asperct ratio, thus: width / height.
* @type {number}
*/
public aspectRatio: number;
/**
* Clear the whole stage every frame? (Default to true)
* @type {boolean}
*/
public clear: bool = true;
/**
* Canvas element used by engine.
* @type {HTMLCanvasElement}
*/
public canvas: HTMLCanvasElement;
/**
* Render context of stage's canvas.
* @type {CanvasRenderingContext2D}
*/
public context: CanvasRenderingContext2D;
/**
* Do not use pause screen when game is paused?
* (Default to false, aka always use PauseScreen)
* @type {boolean}
*/
public disablePauseScreen: bool = false;
/**
* Do not use boot screen when engine starts?
* (Default to false, aka always use BootScreen)
* @type {boolean}
*/
public disableBootScreen: bool = false;
/**
* Offset from this stage to the canvas element.
* @type {Point}
*/
public offset: Point;
/**
* This object manages scaling of the game, see(StageScaleMode).
* @type {StageScaleMode}
*/
public scale: StageScaleMode;
/**
* Which mode will the game be scaled.
* Available: StageScaleMode.EXACT_FIT, StageScaleMode.NO_SCALE, StageScaleMode.SHOW_ALL.
* @type {number}
*/
public scaleMode: number;
/**
* Minimal scale factor of x-axis.
* @type {number}
*/
public minScaleX: number = null;
/**
* Maximal scale factor of x-axis.
* @type {number}
*/
public maxScaleX: number = null;
/**
* Minimal scale factor of y-axis.
* @type {number}
*/
public minScaleY: number = null;
/**
* Maximal scale factor of y-axis.
* @type {number}
*/
public maxScaleY: number = null;
/**
* Update stage for rendering. This will handle scaling, clearing
* and PauseScreen/BootScreen updating and rendering.
*/
public update() {
this.scale.update();
@@ -103,6 +198,9 @@ module Phaser {
}
/**
* This method will be called when canvas element's visibility changed.
*/
private visibilityChange(event) {
if (this.disablePauseScreen)
@@ -144,10 +242,25 @@ module Phaser {
}
/**
* Canvas strokeStyle.
* @type {string}
*/
public strokeStyle: string;
/**
* Canvas lineWidth.
* @type {number}
*/
public lineWidth: number;
/**
* Canvas fillStyle.
* @type {string}
*/
public fillStyle: string;
/**
* Save current canvas properties (strokeStyle, lineWidth and fillStyle) for later using.
*/
public saveCanvasValues() {
this.strokeStyle = this.context.strokeStyle;
@@ -156,6 +269,9 @@ module Phaser {
}
/**
* Restore current canvas values (strokeStyle, lineWidth and fillStyle) with saved values.
*/
public restoreCanvasValues() {
this.context.strokeStyle = this.strokeStyle;
+154
View File
@@ -10,6 +10,11 @@ module Phaser {
export class State {
/**
* State constructor
*
* Create a new <code>State</code>.
*/
constructor(game: Game) {
this.game = game;
@@ -29,71 +34,220 @@ module Phaser {
}
/**
* Reference to Game.
*/
public game: Game;
/**
* Currently used camera.
* @type {Camera}
*/
public camera: Camera;
/**
* Reference to the assets cache.
* @type {Cache}
*/
public cache: Cache;
/**
* Reference to the collision helper.
* @type {Collision}
*/
public collision: Collision;
/**
* Reference to the input manager
* @type {Input}
*/
public input: Input;
/**
* Reference to the assets loader.
* @type {Loader}
*/
public loader: Loader;
/**
* Reference to the math helper.
* @type {GameMath}
*/
public math: GameMath;
/**
* Reference to the motion helper.
* @type {Motion}
*/
public motion: Motion;
/**
* Reference to the sound manager.
* @type {SoundManager}
*/
public sound: SoundManager;
/**
* Reference to the stage.
* @type {Stage}
*/
public stage: Stage;
/**
* Reference to game clock.
* @type {Time}
*/
public time: Time;
/**
* Reference to the tween manager.
* @type {TweenManager}
*/
public tweens: TweenManager;
/**
* Reference to the world.
* @type {World}
*/
public world: World;
// Overload these in your own States
/**
* Override this method to add some load operations.
* If you need to use the loader, you may need to use them here.
*/
public init() { }
/**
* This method is called after the game engine successfully switches states.
* Feel free to add any setup code here.(Do not load anything here, override init() instead)
*/
public create() { }
/**
* Put update logic here.
*/
public update() { }
/**
* Put render operations here.
*/
public render() { }
/**
* This method will be called when game paused.
*/
public paused() { }
// Handy Proxy methods
/**
* Create a new camera with specific position and size.
*
* @param x X position of the new camera.
* @param y Y position of the new camera.
* @param width Width of the new camera.
* @param height Height of the new camera.
* @returns {Camera=} The newly created camera object.
*/
public createCamera(x: number, y: number, width: number, height: number): Camera {
return this.game.world.createCamera(x, y, width, height);
}
/**
* Create a new GeomSprite with specific position.
*
* @param x X position of the new geom sprite.
* @param y Y position of the new geom sprite.
* @returns {GeomSprite=} The newly created geom sprite object.
*/
public createGeomSprite(x: number, y: number): GeomSprite {
return this.world.createGeomSprite(x, y);
}
/**
* Create a new Sprite with specific position and sprite sheet key.
*
* @param x X position of the new sprite.
* @param y Y position of the new sprite.
* @param key Optinal, key for the sprite sheet you want it to use.
* @returns {Sprite=} The newly created sprite object.
*/
public createSprite(x: number, y: number, key?: string = ''): Sprite {
return this.game.world.createSprite(x, y, key);
}
/**
* Create a new DynamicTexture with specific size.
*
* @param width Width of the texture.
* @param height Height of the texture.
* @returns {DynamicTexture=} The newly created dynamic texture object.
*/
public createDynamicTexture(width: number, height: number): DynamicTexture {
return this.game.world.createDynamicTexture(width, height);
}
/**
* Create a new object container.
*
* @param MaxSize Optinal, capacity of this group.
* @returns {Group=} The newly created group.
*/
public createGroup(MaxSize?: number = 0): Group {
return this.game.world.createGroup(MaxSize);
}
/**
* Create a new Particle.
*
* @return {Particle=} The newly created particle object.
*/
public createParticle(): Particle {
return this.game.world.createParticle();
}
/**
* Create a new Emitter.
*
* @param x Optinal, x position of the emitter.
* @param y Optinal, y position of the emitter.
* @param size Optinal, size of this emitter.
* @return {Emitter=} The newly created emitter object.
*/
public createEmitter(x?: number = 0, y?: number = 0, size?: number = 0): Emitter {
return this.game.world.createEmitter(x, y, size);
}
/**
* Create a new ScrollZone object with image key, position and size.
*
* @param key Key to a image you wish this object to use.
* @param x X position of this object.
* @param y Y position of this object.
* @param width Width of this object.
* @param height Heigth of this object.
* @returns {ScrollZone=} The newly created scroll zone object.
*/
public createScrollZone(key: string, x?: number = 0, y?: number = 0, width?: number = 0, height?: number = 0): ScrollZone {
return this.game.world.createScrollZone(key, x, y, width, height);
}
/**
* Create a new Tilemap.
*
* @param key Key for tileset image.
* @param mapData Data of this tilemap.
* @param format Format of map data. (Tilemap.FORMAT_CSV or Tilemap.FORMAT_TILED_JSON)
* @param resizeWorld Optinal, resize the world to make same as tilemap?
* @param tileWidth Optinal, width of each tile.
* @param tileHeight Optinal, height of each tile.
* @return {Tilemap=} The newly created tilemap object.
*/
public createTilemap(key: string, mapData: string, format: number, resizeWorld: bool = true, tileWidth?: number = 0, tileHeight?: number = 0): Tilemap {
return this.game.world.createTilemap(key, mapData, format, resizeWorld, tileWidth, tileHeight);
}
/**
* Create a tween object for a specific object.
*
* @param obj Object you wish the tween will affect.
* @return {Phaser.Tween=} The newly created tween object.
*/
public createTween(obj): Tween {
return this.game.tweens.create(obj);
}
/**
* Call this method to see if one object collids another.
* @return {boolean} Whether the given objects or groups collids.
*/
public collide(ObjectOrGroup1: Basic = null, ObjectOrGroup2: Basic = null, NotifyCallback = null): bool {
return this.collision.overlap(ObjectOrGroup1, ObjectOrGroup2, NotifyCallback, Collision.separate);
}
+124
View File
@@ -12,6 +12,13 @@ module Phaser {
export class World {
/**
* World constructor
* Create a new <code>World</code> with specific width and height.
*
* @param width Width of the world bound.
* @param height Height of the world bound.
*/
constructor(game: Game, width: number, height: number) {
this._game = game;
@@ -28,13 +35,34 @@ module Phaser {
}
/**
* Local private reference to game.
*/
private _game: Game;
/**
* Camera manager of this world.
* @type {CameraManager}
*/
public cameras: CameraManager;
/**
* Object container stores every object created with `create*` methods.
* @type {Group}
*/
public group: Group;
/**
* Bound of this world that objects can not escape from.
* @type {Rectangle}
*/
public bounds: Rectangle;
/**
* @type {number}
*/
public worldDivisions: number;
/**
* This is called automatically every frame, and is where main logic performs.
*/
public update() {
this.group.preUpdate();
@@ -45,6 +73,9 @@ module Phaser {
}
/**
* Render every thing to the screen, automatically called after update().
*/
public render() {
// Unlike in flixel our render process is camera driven, not group driven
@@ -52,6 +83,9 @@ module Phaser {
}
/**
* Clean up memory.
*/
public destroy() {
this.group.destroy();
@@ -62,6 +96,14 @@ module Phaser {
// World methods
/**
* Update size of this world with specific width and height.
* You can choose update camera bounds automatically or not.
*
* @param width New width of the world.
* @param height New height of the world.
* @param updateCameraBounds Optinal, update camera bounds automatically or not. Default to true.
*/
public setSize(width: number, height: number, updateCameraBounds: bool = true) {
this.bounds.width = width;
@@ -108,48 +150,130 @@ module Phaser {
// Cameras
/**
* Create a new camera with specific position and size.
*
* @param x X position of the new camera.
* @param y Y position of the new camera.
* @param width Width of the new camera.
* @param height Height of the new camera.
* @returns {Camera=} The newly created camera object.
*/
public createCamera(x: number, y: number, width: number, height: number): Camera {
return this.cameras.addCamera(x, y, width, height);
}
/**
* Remove a new camera with its id.
*
* @param id ID of the camera you want to remove.
* @returns {boolean} True if successfully removed the camera, otherwise return false.
*/
public removeCamera(id: number): bool {
return this.cameras.removeCamera(id);
}
/**
* Get all the cameras.
*
* @returns {array} An array contains all the cameras.
*/
public getAllCameras(): Camera[] {
return this.cameras.getAll();
}
// Game Objects
/**
* Create a new Sprite with specific position and sprite sheet key.
*
* @param x X position of the new sprite.
* @param y Y position of the new sprite.
* @param key Optinal, key for the sprite sheet you want it to use.
* @returns {Sprite=} The newly created sprite object.
*/
public createSprite(x: number, y: number, key?: string = ''): Sprite {
return <Sprite> this.group.add(new Sprite(this._game, x, y, key));
}
/**
* Create a new GeomSprite with specific position.
*
* @param x X position of the new geom sprite.
* @param y Y position of the new geom sprite.
* @returns {GeomSprite=} The newly created geom sprite object.
*/
public createGeomSprite(x: number, y: number): GeomSprite {
return <GeomSprite> this.group.add(new GeomSprite(this._game, x, y));
}
/**
* Create a new DynamicTexture with specific size.
*
* @param width Width of the texture.
* @param height Height of the texture.
* @returns {DynamicTexture=} The newly created dynamic texture object.
*/
public createDynamicTexture(width: number, height: number): DynamicTexture {
return new DynamicTexture(this._game, width, height);
}
/**
* Create a new object container.
*
* @param MaxSize Optinal, capacity of this group.
* @returns {Group=} The newly created group.
*/
public createGroup(MaxSize?: number = 0): Group {
return <Group> this.group.add(new Group(this._game, MaxSize));
}
/**
* Create a new ScrollZone object with image key, position and size.
*
* @param key Key to a image you wish this object to use.
* @param x X position of this object.
* @param y Y position of this object.
* @param width Width of this object.
* @param height Heigth of this object.
* @returns {ScrollZone=} The newly created scroll zone object.
*/
public createScrollZone(key: string, x?: number = 0, y?: number = 0, width?: number = 0, height?: number = 0): ScrollZone {
return <ScrollZone> this.group.add(new ScrollZone(this._game, key, x, y, width, height));
}
/**
* Create a new Tilemap.
*
* @param key Key for tileset image.
* @param mapData Data of this tilemap.
* @param format Format of map data. (Tilemap.FORMAT_CSV or Tilemap.FORMAT_TILED_JSON)
* @param resizeWorld Optinal, resize the world to make same as tilemap?
* @param tileWidth Optinal, width of each tile.
* @param tileHeight Optinal, height of each tile.
* @return {Tilemap=} The newly created tilemap object.
*/
public createTilemap(key: string, mapData: string, format: number, resizeWorld: bool = true, tileWidth?: number = 0, tileHeight?: number = 0): Tilemap {
return <Tilemap> this.group.add(new Tilemap(this._game, key, mapData, format, resizeWorld, tileWidth, tileHeight));
}
/**
* Create a new Particle.
*
* @return {Particle=} The newly created particle object.
*/
public createParticle(): Particle {
return new Particle(this._game);
}
/**
* Create a new Emitter.
*
* @param x Optinal, x position of the emitter.
* @param y Optinal, y position of the emitter.
* @param size Optinal, size of this emitter.
* @return {Emitter=} The newly created emitter object.
*/
public createEmitter(x?: number = 0, y?: number = 0, size?: number = 0): Emitter {
return <Emitter> this.group.add(new Emitter(this._game, x, y, size));
}