diff --git a/Phaser/gameobjects/ScrollRegion.ts b/Phaser/gameobjects/ScrollRegion.ts
index 4f8370f6..5d3149b5 100644
--- a/Phaser/gameobjects/ScrollRegion.ts
+++ b/Phaser/gameobjects/ScrollRegion.ts
@@ -12,6 +12,17 @@ module Phaser {
export class ScrollRegion{
+ /**
+ * ScrollRegion constructor
+ * Create a new ScrollRegion.
+ *
+ * @param x {number} X position in world coordinate.
+ * @param y {number} Y position in world coordinate.
+ * @param width {number} Width of this object.
+ * @param height {number} Height of this object.
+ * @param speedX {number} X-axis scrolling speed.
+ * @param speedY {number} Y-axis scrolling speed.
+ */
constructor(x: number, y: number, width: number, height: number, speedX:number, speedY:number) {
// Our seamless scrolling quads
@@ -38,9 +49,21 @@ module Phaser {
private _inverseWidth: number = 0;
private _inverseHeight: number = 0;
+ /**
+ * Will this region be rendered? (default to true)
+ * @type {boolean}
+ */
public visible: bool = true;
+ /**
+ * Region scrolling speed.
+ * @type {MicroPoint}
+ */
public scrollSpeed: MicroPoint;
+ /**
+ * Update region scrolling with tick time.
+ * @param delta {number} Elapsed time since last update.
+ */
public update(delta: number) {
this._scroll.x += this.scrollSpeed.x;
@@ -102,6 +125,15 @@ module Phaser {
}
+ /**
+ * Render this region to specific context.
+ * @param context {CanvasRenderingContext2D} Canvas context this region will be rendered to.
+ * @param texture {object} The texture to be rendered.
+ * @param dx {number} X position in world coordinate.
+ * @param dy {number} Y position in world coordinate.
+ * @param width {number} Width of this region to be rendered.
+ * @param height {number} Height of this region to be rendered.
+ */
public render(context:CanvasRenderingContext2D, texture, dx: number, dy: number, dw: number, dh: number) {
if (this.visible == false)
@@ -126,6 +158,21 @@ module Phaser {
}
+ /**
+ * Crop part of the texture and render it to the given context.
+ * @param context {CanvasRenderingContext2D} Canvas context the texture will be rendered to.
+ * @param texture {object} Texture to be rendered.
+ * @param srcX {number} Target region top-left x coordinate in the texture.
+ * @param srcX {number} Target region top-left y coordinate in the texture.
+ * @param srcW {number} Target region width in the texture.
+ * @param srcH {number} Target region height in the texture.
+ * @param destX {number} Render region top-left x coordinate in the context.
+ * @param destX {number} Render region top-left y coordinate in the context.
+ * @param destW {number} Target region width in the context.
+ * @param destH {number} Target region height in the context.
+ * @param offsetX {number} X offset to the context.
+ * @param offsetY {number} Y offset to the context.
+ */
private crop(context, texture, srcX, srcY, srcW, srcH, destX, destY, destW, destH, offsetX, offsetY) {
offsetX += destX;
diff --git a/Phaser/gameobjects/ScrollZone.ts b/Phaser/gameobjects/ScrollZone.ts
index 95135390..92864692 100644
--- a/Phaser/gameobjects/ScrollZone.ts
+++ b/Phaser/gameobjects/ScrollZone.ts
@@ -15,6 +15,17 @@ module Phaser {
export class ScrollZone extends GameObject {
+ /**
+ * ScrollZone constructor
+ * Create a new ScrollZone.
+ *
+ * @param game {Phaser.Game} Current game instance.
+ * @param key {string} Asset key for image texture of this object.
+ * @param x {number} X position in world coordinate.
+ * @param y {number} Y position in world coordinate.
+ * @param width {number} Optional, width of this object.
+ * @param height {number} Optional, height of this object.
+ */
constructor(game: Game, key:string, x: number = 0, y: number = 0, width?: number = 0, height?: number = 0) {
super(game, x, y, width, height);
@@ -49,19 +60,63 @@ module Phaser {
}
+ /**
+ * Texture of this object.
+ */
private _texture;
+ /**
+ * If this zone is larger than texture image, this will be filled with a pattern of texture.
+ * @type {DynamicTexture}
+ */
private _dynamicTexture: DynamicTexture = null;
- // local rendering related temp vars to help avoid gc spikes
+ /**
+ * Local rendering related temp vars to help avoid gc spikes.
+ * @type {number}
+ */
private _dx: number = 0;
+ /**
+ * Local rendering related temp vars to help avoid gc spikes.
+ * @type {number}
+ */
private _dy: number = 0;
+ /**
+ * Local rendering related temp vars to help avoid gc spikes.
+ * @type {number}
+ */
private _dw: number = 0;
+ /**
+ * Local rendering related temp vars to help avoid gc spikes.
+ * @type {number}
+ */
private _dh: number = 0;
+ /**
+ * Current region this zone is scrolling.
+ * @type {ScrollRegion}
+ */
public currentRegion: ScrollRegion;
+ /**
+ * Array contains all added regions.
+ * @type {ScrollRegion[]}
+ */
public regions: ScrollRegion[];
+ /**
+ * Flip this zone vertically? (default to false)
+ * @type {boolean}
+ */
public flipped: bool = false;
+ /**
+ * Add a new region to this zone.
+ * @param x {number} X position of the new region.
+ * @param y {number} Y position of the new region.
+ * @param width {number} Width of the new region.
+ * @param height {number} Height of the new region.
+ * @param speedX {number} Optional, x-axis scrolling speed.
+ * @param speedY {number} Optional, y-axis scrolling speed.
+ * @return {ScrollRegion} The newly added region.
+ */
public addRegion(x: number, y: number, width: number, height: number, speedX?:number = 0, speedY?:number = 0):ScrollRegion {
if (x > this.width || y > this.height || x < 0 || y < 0 || (x + width) > this.width || (y + height) > this.height)
@@ -78,6 +133,11 @@ module Phaser {
}
+ /**
+ * Set scrolling speed of current region.
+ * @param x {number} X speed of current region.
+ * @param y {number} Y speed of current region.
+ */
public setSpeed(x: number, y: number) {
if (this.currentRegion)
@@ -89,6 +149,9 @@ module Phaser {
}
+ /**
+ * Update regions.
+ */
public update() {
for (var i = 0; i < this.regions.length; i++)
@@ -98,8 +161,13 @@ module Phaser {
}
+ /**
+ * Check whether this zone is visible in a specific camera rectangle.
+ * @param camera {Rectangle} The rectangle you want to check.
+ * @return {boolean} Return true if bound of this zone intersects the given rectangle, otherwise return false.
+ */
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);
@@ -116,6 +184,13 @@ module Phaser {
}
+ /**
+ * Render this zone object to a specific camera.
+ * @param camera {Camera} The camera this object will be render to.
+ * @param cameraOffsetX {number} X offset of camera.
+ * @param cameraOffsetY {number} Y offset of camera.
+ * @return Return false if not rendered, otherwise return true.
+ */
public render(camera: Camera, cameraOffsetX: number, cameraOffsetY: number) {
// Render checks
@@ -189,6 +264,10 @@ module Phaser {
}
+ /**
+ * Create repeating texture with _texture, and store it into the _dynamicTexture.
+ * Used to create texture when texture image is small than size of the zone.
+ */
private createRepeatingTexture(regionWidth: number, regionHeight: number) {
// Work out how many we'll need of the source image to make it tile properly
diff --git a/Phaser/gameobjects/Tilemap.ts b/Phaser/gameobjects/Tilemap.ts
index 9a346705..9ae037fa 100644
--- a/Phaser/gameobjects/Tilemap.ts
+++ b/Phaser/gameobjects/Tilemap.ts
@@ -14,6 +14,18 @@ module Phaser {
export class Tilemap extends GameObject {
+ /**
+ * Tilemap constructor
+ * Create a new Tilemap.
+ *
+ * @param game {Phaser.Game} Current game instance.
+ * @param key {string} Asset key for this map.
+ * @param mapData {string} Data of this map. (a big 2d array, normally in csv)
+ * @param format {number} Format of this map data, available: Tilemap.FORMAT_CSV or Tilemap.FORMAT_TILED_JSON.
+ * @param resizeWorld {boolean} Resize the world bound automatically based on this tilemap?
+ * @param tileWidth {number} Width of tiles in this map.
+ * @param tileHeight {number} Height of tiles in this map.
+ */
constructor(game: Game, key: string, mapData: string, format: number, resizeWorld: bool = true, tileWidth?: number = 0, tileHeight?: number = 0) {
super(game);
@@ -45,20 +57,64 @@ module Phaser {
private _tempCollisionData;
+ /**
+ * Tilemap data format enum: CSV.
+ * @type {number}
+ */
public static FORMAT_CSV: number = 0;
+ /**
+ * Tilemap data format enum: Tiled JSON.
+ * @type {number}
+ */
public static FORMAT_TILED_JSON: number = 1;
+ /**
+ * Array contains tile objects of this map.
+ * @type {Tile[]}
+ */
public tiles : Tile[];
+ /**
+ * Array contains tilemap layer objects of this map.
+ * @type {TilemapLayer[]}
+ */
public layers : TilemapLayer[];
+ /**
+ * Current tilemap layer.
+ * @type {TilemapLayer}
+ */
public currentLayer: TilemapLayer;
+ /**
+ * The tilemap layer for collision.
+ * @type {TilemapLayer}
+ */
public collisionLayer: TilemapLayer;
+ /**
+ * Tilemap collision callback.
+ * @type {function}
+ */
public collisionCallback = null;
+ /**
+ * Context for the collision callback called with.
+ */
public collisionCallbackContext;
+ /**
+ * Format of this tilemap data. Available values: Tilemap.FORMAT_CSV or Tilemap.FORMAT_TILED_JSON.
+ * @type {number}
+ */
public mapFormat: number;
+ /**
+ * Inherited update method.
+ */
public update() {
}
+ /**
+ * Render this tilemap to a specific camera with specific offset.
+ * @param camera {Camera} The camera this tilemap will be rendered to.
+ * @param cameraOffsetX {number} X offset of the camera.
+ * @param cameraOffsetY {number} Y offset of the camera.
+ */
public render(camera: Camera, cameraOffsetX: number, cameraOffsetY: number) {
if (this.cameraBlacklist.indexOf(camera.ID) == -1)
@@ -72,6 +128,13 @@ module Phaser {
}
+ /**
+ * Parset csv map data and generate tiles.
+ * @param data {string} CSV map data.
+ * @param key {string} Asset key for tileset image.
+ * @param tileWidth {number} Width of its tile.
+ * @param tileHeight {number} Height of its tile.
+ */
private parseCSV(data: string, key: string, tileWidth: number, tileHeight: number) {
var layer: TilemapLayer = new TilemapLayer(this._game, this, key, Tilemap.FORMAT_CSV, 'TileLayerCSV' + this.layers.length.toString(), tileWidth, tileHeight);
@@ -103,6 +166,11 @@ module Phaser {
}
+ /**
+ * Parset JSON map data and generate tiles.
+ * @param data {string} JSON map data.
+ * @param key {string} Asset key for tileset image.
+ */
private parseTiledJSON(data: string, key: string) {
// Trim any rogue whitespace from the data
@@ -113,7 +181,7 @@ module Phaser {
for (var i = 0; i < json.layers.length; i++)
{
var layer: TilemapLayer = new TilemapLayer(this._game, this, key, Tilemap.FORMAT_TILED_JSON, json.layers[i].name, json.tilewidth, json.tileheight);
-
+
layer.alpha = json.layers[i].opacity;
layer.visible = json.layers[i].visible;
layer.tileMargin = json.tilesets[0].margin;
@@ -155,6 +223,10 @@ module Phaser {
}
+ /**
+ * Create tiles of given quantity.
+ * @param qty {number} Quentity of tiles to be generated.
+ */
private generateTiles(qty:number) {
for (var i = 0; i < qty; i++)
@@ -174,6 +246,11 @@ module Phaser {
// Tile Collision
+ /**
+ * Set callback to be called when this tilemap collides.
+ * @param context {object} Callback will be called with this context.
+ * @param callback {function} Callback function.
+ */
public setCollisionCallback(context, callback) {
this.collisionCallbackContext = context;
@@ -181,6 +258,15 @@ module Phaser {
}
+ /**
+ * Set collision configs of tiles in a range index.
+ * @param start {number} First index of tiles.
+ * @param end {number} Last index of tiles.
+ * @param collision {number} Bit field of flags. (see Tile.allowCollision)
+ * @param resetCollisions {boolean} Reset collision flags before set.
+ * @param separateX {boolean} Enable seprate at x-axis.
+ * @param separateY {boolean} Enable seprate at y-axis.
+ */
public setCollisionRange(start: number, end: number, collision?:number = Collision.ANY, resetCollisions?: bool = false, separateX?: bool = true, separateY?: bool = true) {
for (var i = start; i < end; i++)
@@ -190,6 +276,14 @@ module Phaser {
}
+ /**
+ * Set collision configs of tiles with given index.
+ * @param values {number[]} Index array which contains all tile indexes. The tiles with those indexes will be setup with rest parameters.
+ * @param collision {number} Bit field of flags. (see Tile.allowCollision)
+ * @param resetCollisions {boolean} Reset collision flags before set.
+ * @param separateX {boolean} Enable seprate at x-axis.
+ * @param separateY {boolean} Enable seprate at y-axis.
+ */
public setCollisionByIndex(values:number[], collision?:number = Collision.ANY, resetCollisions?: bool = false, separateX?: bool = true, separateY?: bool = true) {
for (var i = 0; i < values.length; i++)
@@ -201,6 +295,11 @@ module Phaser {
// Tile Management
+ /**
+ * Get the tile by its index.
+ * @param value {number} Index of the tile you want to get.
+ * @return {Tile} The tile with given index.
+ */
public getTileByIndex(value: number):Tile {
if (this.tiles[value])
@@ -212,12 +311,26 @@ module Phaser {
}
+ /**
+ * Get the tile located at specific position and layer.
+ * @param x {number} X position of this tile located.
+ * @param y {number} Y position of this tile located.
+ * @param layer {number} Optional, layer of this tile located.
+ * @return {Tile} The tile with specific properties.
+ */
public getTile(x: number, y: number, layer?: number = 0):Tile {
return this.tiles[this.layers[layer].getTileIndex(x, y)];
}
+ /**
+ * Get the tile located at specific position (in world coordinate) and layer. (thus you give a position of a point which is within the tile)
+ * @param x {number} X position of the point in target tile.
+ * @param x {number} Y position of the point in target tile.
+ * @param layer {number} Optional, layer of this tile located.
+ * @return {Tile} The tile with specific properties.
+ */
public getTileFromWorldXY(x: number, y: number, layer?: number = 0):Tile {
return this.tiles[this.layers[layer].getTileFromWorldXY(x, y)];
@@ -230,6 +343,11 @@ module Phaser {
}
+ /**
+ * Get tiles overlaps the given object.
+ * @param object {GameObject} Tiles you want to get that overlaps this.
+ * @return {array} Array with tiles informations. (Each contains x, y and the tile.)
+ */
public getTileOverlaps(object: GameObject) {
return this.currentLayer.getTileOverlaps(object);
@@ -237,6 +355,13 @@ module Phaser {
}
// COLLIDE
+ /**
+ * Check whether this tilemap collides with the given game object or group of objects.
+ * @param objectOrGroup {function} Target object of group you want to check.
+ * @param callback {function} This is called if objectOrGroup collides the tilemap.
+ * @param context {object} Callback will be called with this context.
+ * @return {boolean} Return true if this collides with given object, otherwise return false.
+ */
public collide(objectOrGroup = null, callback = null, context = null) {
if (callback !== null && context !== null)
@@ -262,6 +387,11 @@ module Phaser {
}
+ /**
+ * Check whether this tilemap collides with the given game object.
+ * @param object {GameObject} Target object you want to check.
+ * @return {boolean} Return true if this collides with given object, otherwise return false.
+ */
public collideGameObject(object: GameObject): bool {
if (object !== this && object.immovable == false && object.exists == true && object.allowCollisions != Collision.NONE)
@@ -282,6 +412,13 @@ module Phaser {
}
+ /**
+ * Set a tile to a specific layer.
+ * @param x {number} X position of this tile.
+ * @param y {number} Y position of this tile.
+ * @param index {number} The index of this tile type in the core map data.
+ * @param layer {number} Optional, which layer you want to set the tile to.
+ */
public putTile(x: number, y: number, index: number, layer?: number = 0) {
this.layers[layer].putTile(x, y, index);
diff --git a/Phaser/system/Device.ts b/Phaser/system/Device.ts
index cd1c7161..754a0922 100644
--- a/Phaser/system/Device.ts
+++ b/Phaser/system/Device.ts
@@ -12,10 +12,8 @@ module Phaser {
export class Device {
/**
- *
- * @constructor
- * @return {Device} This Object
- */
+ * Device constructor
+ */
constructor() {
this._checkAudio();
@@ -29,260 +27,229 @@ module Phaser {
// Operating System
+ /**
+ * Is running desktop?
+ * @type {boolean}
+ */
public desktop: bool = false;
/**
- *
- * @property iOS
- * @type Boolean
- */
+ * Is running on iOS?
+ * @type {boolean}
+ */
public iOS: bool = false;
- /**
- *
- * @property android
- * @type Boolean
- */
+ /**
+ * Is running on android?
+ * @type {boolean}
+ */
public android: bool = false;
/**
- *
- * @property chromeOS
- * @type Boolean
- */
+ * Is running on chromeOS?
+ * @type {boolean}
+ */
public chromeOS: bool = false;
/**
- *
- * @property linux
- * @type Boolean
- */
+ * Is running on linux?
+ * @type {boolean}
+ */
public linux: bool = false;
/**
- *
- * @property maxOS
- * @type Boolean
- */
+ * Is running on maxOS?
+ * @type {boolean}
+ */
public macOS: bool = false;
/**
- *
- * @property windows
- * @type Boolean
- */
+ * Is running on windows?
+ * @type {boolean}
+ */
public windows: bool = false;
// Features
/**
- *
- * @property canvas
- * @type Boolean
- */
+ * Is canvas available?
+ * @type {boolean}
+ */
public canvas: bool = false;
/**
- *
- * @property file
- * @type Boolean
- */
+ * Is file available?
+ * @type {boolean}
+ */
public file: bool = false;
/**
- *
- * @property fileSystem
- * @type Boolean
- */
+ * Is fileSystem available?
+ * @type {boolean}
+ */
public fileSystem: bool = false;
/**
- *
- * @property localStorage
- * @type Boolean
- */
+ * Is localStorage available?
+ * @type {boolean}
+ */
public localStorage: bool = false;
/**
- *
- * @property webGL
- * @type Boolean
- */
+ * Is webGL available?
+ * @type {boolean}
+ */
public webGL: bool = false;
/**
- *
- * @property worker
- * @type Boolean
- */
+ * Is worker available?
+ * @type {boolean}
+ */
public worker: bool = false;
/**
- *
- * @property touch
- * @type Boolean
- */
+ * Is touch available?
+ * @type {boolean}
+ */
public touch: bool = false;
/**
- *
- * @property css3D
- * @type Boolean
- */
+ * Is css3D available?
+ * @type {boolean}
+ */
public css3D: bool = false;
// Browser
/**
- *
- * @property arora
- * @type Boolean
- */
+ * Is running in arora?
+ * @type {boolean}
+ */
public arora: bool = false;
/**
- *
- * @property chrome
- * @type Boolean
- */
+ * Is running in chrome?
+ * @type {boolean}
+ */
public chrome: bool = false;
/**
- *
- * @property epiphany
- * @type Boolean
- */
+ * Is running in epiphany?
+ * @type {boolean}
+ */
public epiphany: bool = false;
/**
- *
- * @property firefox
- * @type Boolean
- */
+ * Is running in firefox?
+ * @type {boolean}
+ */
public firefox: bool = false;
/**
- *
- * @property ie
- * @type Boolean
- */
+ * Is running in ie?
+ * @type {boolean}
+ */
public ie: bool = false;
/**
- *
- * @property ieVersion
- * @type Number
- */
+ * Version of ie?
+ * @type Number
+ */
public ieVersion: number = 0;
/**
- *
- * @property mobileSafari
- * @type Boolean
- */
+ * Is running in mobileSafari?
+ * @type {boolean}
+ */
public mobileSafari: bool = false;
/**
- *
- * @property midori
- * @type Boolean
- */
+ * Is running in midori?
+ * @type {boolean}
+ */
public midori: bool = false;
/**
- *
- * @property opera
- * @type Boolean
- */
+ * Is running in opera?
+ * @type {boolean}
+ */
public opera: bool = false;
/**
- *
- * @property safari
- * @type Boolean
- */
+ * Is running in safari?
+ * @type {boolean}
+ */
public safari: bool = false;
public webApp: bool = false;
// Audio
/**
- *
- * @property audioData
- * @type Boolean
- */
+ * Is audioData available?
+ * @type {boolean}
+ */
public audioData: bool = false;
/**
- *
- * @property webaudio
- * @type Boolean
- */
+ * Is webaudio available?
+ * @type {boolean}
+ */
public webaudio: bool = false;
/**
- *
- * @property ogg
- * @type Boolean
- */
+ * Is ogg available?
+ * @type {boolean}
+ */
public ogg: bool = false;
/**
- *
- * @property mp3
- * @type Boolean
- */
+ * Is mp3 available?
+ * @type {boolean}
+ */
public mp3: bool = false;
/**
- *
- * @property wav
- * @type Boolean
- */
+ * Is wav available?
+ * @type {boolean}
+ */
public wav: bool = false;
/**
- *
- * @property m4a
- * @type Boolean
- */
+ * Is m4a available?
+ * @type {boolean}
+ */
public m4a: bool = false;
// Device
/**
- *
- * @property iPhone
- * @type Boolean
- */
+ * Is running on iPhone?
+ * @type {boolean}
+ */
public iPhone: bool = false;
/**
- *
- * @property iPhone4
- * @type Boolean
- */
+ * Is running on iPhone4?
+ * @type {boolean}
+ */
public iPhone4: bool = false;
/**
- *
- * @property iPad
- * @type Boolean
- */
+ * Is running on iPad?
+ * @type {boolean}
+ */
public iPad: bool = false;
/**
- *
- * @property pixelRatio
- * @type Number
- */
+ * PixelRatio of the host device?
+ * @type Number
+ */
public pixelRatio: number = 0;
/**
- *
- * @method _checkOS
- * @private
- */
+ * Check which OS is game running on.
+ * @private
+ */
private _checkOS() {
var ua = navigator.userAgent;
@@ -320,10 +287,9 @@ module Phaser {
}
/**
- *
- * @method _checkFeatures
- * @private
- */
+ * Check HTML5 features of the host environment.
+ * @private
+ */
private _checkFeatures() {
this.canvas = !!window['CanvasRenderingContext2D'];
@@ -350,10 +316,9 @@ module Phaser {
}
/**
- *
- * @method _checkBrowser
- * @private
- */
+ * Check what browser is game running in.
+ * @private
+ */
private _checkBrowser() {
var ua = navigator.userAgent;
@@ -405,10 +370,9 @@ module Phaser {
}
/**
- *
- * @method _checkAudio
- * @private
- */
+ * Check audio support.
+ * @private
+ */
private _checkAudio() {
this.audioData = !!(window['Audio']);
@@ -449,10 +413,9 @@ module Phaser {
}
/**
- *
- * @method _checkDevice
- * @private
- */
+ * Check PixelRatio of devices.
+ * @private
+ */
private _checkDevice() {
this.pixelRatio = window['devicePixelRatio'] || 1;
@@ -463,10 +426,9 @@ module Phaser {
}
/**
- *
- * @method _checkCSS3D
- * @private
- */
+ * Check whether the host environment support 3D CSS.
+ * @private
+ */
private _checkCSS3D() {
var el = document.createElement('p');
@@ -498,10 +460,9 @@ module Phaser {
}
/**
- *
- * @method getAll
- * @return {String}
- */
+ * Get all informations of host device.
+ * @return {string} Informations in a string.
+ */
public getAll(): string {
var output: string = '';
diff --git a/Phaser/system/TilemapLayer.ts b/Phaser/system/TilemapLayer.ts
index c4e15101..15d8a893 100644
--- a/Phaser/system/TilemapLayer.ts
+++ b/Phaser/system/TilemapLayer.ts
@@ -10,6 +10,18 @@ module Phaser {
export class TilemapLayer {
+ /**
+ * TilemapLayer constructor
+ * Create a new TilemapLayer.
+ *
+ * @param game {Phaser.Game} Current game instance.
+ * @param parent {Tilemap} The tilemap that contains this layer.
+ * @param key {string} Asset key for this map.
+ * @param mapFormat {number} Format of this map data, available: Tilemap.FORMAT_CSV or Tilemap.FORMAT_TILED_JSON.
+ * @param name {string} Name of this layer, so you can get this layer by its name.
+ * @param tileWidth {number} Width of tiles in this map.
+ * @param tileHeight {number} Height of tiles in this map.
+ */
constructor(game: Game, parent:Tilemap, key: string, mapFormat: number, name: string, tileWidth: number, tileHeight: number) {
this._game = game;
@@ -28,8 +40,18 @@ module Phaser {
}
+ /**
+ * Local private reference to game.
+ */
private _game: Game;
+ /**
+ * The tilemap that contains this layer.
+ * @type {Tilemap}
+ */
private _parent: Tilemap;
+ /**
+ * Tileset of this layer.
+ */
private _texture;
private _tileOffsets;
private _startX: number = 0;
@@ -51,30 +73,103 @@ module Phaser {
private _tempTileBlock;
private _tempBlockResults;
+ /**
+ * Name of this layer, so you can get this layer by its name.
+ * @type {string}
+ */
public name: string;
+ /**
+ * Opacity of this layer.
+ * @type {number}
+ */
public alpha: number = 1;
+ /**
+ * Controls whether update() and draw() are automatically called.
+ * @type {boolean}
+ */
public exists: bool = true;
+ /**
+ * Controls whether draw() are automatically called.
+ * @type {boolean}
+ */
public visible: bool = true;
//public scrollFactor: MicroPoint;
+ /**
+ * @type {string}
+ */
public orientation: string;
+ /**
+ * Properties of this map layer. (normally set by map editors)
+ */
public properties: {};
+ /**
+ * Map data in a 2d array, its element is a index number for that tile.
+ * @type {number[][]}
+ */
public mapData;
+ /**
+ * Format of this map data, available: Tilemap.FORMAT_CSV or Tilemap.FORMAT_TILED_JSON.
+ */
public mapFormat: number;
+ /**
+ * It's width and height are in tiles instead of pixels.
+ * @type {Rectangle}
+ */
public boundsInTiles: Rectangle;
+ /**
+ * Width of each tile.
+ * @type {number}
+ */
public tileWidth: number;
+ /**
+ * Height of a single tile.
+ * @type {number}
+ */
public tileHeight: number;
+ /**
+ * How many tiles in each row.
+ * Read-only variable, do NOT recommend changing after the map is loaded!
+ * @type {number}
+ */
public widthInTiles: number = 0;
+ /**
+ * How many tiles in each column.
+ * Read-only variable, do NOT recommend changing after the map is loaded!
+ * @type {number}
+ */
public heightInTiles: number = 0;
+ /**
+ * Read-only variable, do NOT recommend changing after the map is loaded!
+ * @type {number}
+ */
public widthInPixels: number = 0;
+ /**
+ * Read-only variable, do NOT recommend changing after the map is loaded!
+ * @type {number}
+ */
public heightInPixels: number = 0;
+ /**
+ * Distance between REAL tiles to the tileset texture bound.
+ * @type {number}
+ */
public tileMargin: number = 0;
+ /**
+ * Distance between every 2 neighbor tile in the tileset texture.
+ * @type {number}
+ */
public tileSpacing: number = 0;
+ /**
+ * Set a specific tile with its x and y in tiles.
+ * @param x {number} X position of this tile.
+ * @param y {number} Y position of this tile.
+ * @param index {number} The index of this tile type in the core map data.
+ */
public putTile(x: number, y: number, index: number) {
x = this._game.math.snapToFloor(x, this.tileWidth) / this.tileWidth;
@@ -90,6 +185,15 @@ module Phaser {
}
+ /**
+ * Swap tiles with 2 kinds of indexes.
+ * @param tileA {number} First tile index.
+ * @param tileB {number} Second tile index.
+ * @param x {number} Optional, specify a rectangle of tiles to operate. The x position in tiles of rectangle's left-top corner.
+ * @param y {number} Optional, specify a rectangle of tiles to operate. The y position in tiles of rectangle's left-top corner.
+ * @param width {number} Optional, specify a rectangle of tiles to operate. The width in tiles.
+ * @param height {number} Optional, specify a rectangle of tiles to operate. The height in tiles.
+ */
public swapTile(tileA: number, tileB: number, x?: number = 0, y?: number = 0, width?: number = this.widthInTiles, height?: number = this.heightInTiles) {
this.getTempBlock(x, y, width, height);
@@ -120,6 +224,14 @@ module Phaser {
}
+ /**
+ * Fill a tile block with a specific tile index.
+ * @param index {number} Index of tiles you want to fill with.
+ * @param x {number} Optional, x position (in tiles) of block's left-top corner.
+ * @param y {number} Optional, y position (in tiles) of block's left-top corner.
+ * @param width {number} Optional, width of block.
+ * @param height {number} Optional, height of block.
+ */
public fillTile(index: number, x?: number = 0, y?: number = 0, width?: number = this.widthInTiles, height?: number = this.heightInTiles) {
this.getTempBlock(x, y, width, height);
@@ -131,6 +243,14 @@ module Phaser {
}
+ /**
+ * Set random tiles to a specific tile block.
+ * @param tiles {number[]} Tiles with indexes in this array will be randomly set to the given block.
+ * @param x {number} Optional, x position (in tiles) of block's left-top corner.
+ * @param y {number} Optional, y position (in tiles) of block's left-top corner.
+ * @param width {number} Optional, width of block.
+ * @param height {number} Optional, height of block.
+ */
public randomiseTiles(tiles: number[], x?: number = 0, y?: number = 0, width?: number = this.widthInTiles, height?: number = this.heightInTiles) {
this.getTempBlock(x, y, width, height);
@@ -142,6 +262,15 @@ module Phaser {
}
+ /**
+ * Replace one kind of tiles to another kind.
+ * @param tileA {number} Index of tiles you want to replace.
+ * @param tileB {number} Index of tiles you want to set.
+ * @param x {number} Optional, x position (in tiles) of block's left-top corner.
+ * @param y {number} Optional, y position (in tiles) of block's left-top corner.
+ * @param width {number} Optional, width of block.
+ * @param height {number} Optional, height of block.
+ */
public replaceTile(tileA: number, tileB: number, x?: number = 0, y?: number = 0, width?: number = this.widthInTiles, height?: number = this.heightInTiles) {
this.getTempBlock(x, y, width, height);
@@ -156,6 +285,13 @@ module Phaser {
}
+ /**
+ * Get a tile block with specific position and size.(both are in tiles)
+ * @param x {number} X position of block's left-top corner.
+ * @param y {number} Y position of block's left-top corner.
+ * @param width {number} Width of block.
+ * @param height {number} Height of block.
+ */
public getTileBlock(x: number, y: number, width: number, height: number) {
var output = [];
@@ -171,6 +307,11 @@ module Phaser {
}
+ /**
+ * Get a tile with specific position (in world coordinate). (thus you give a position of a point which is within the tile)
+ * @param x {number} X position of the point in target tile.
+ * @param x {number} Y position of the point in target tile.
+ */
public getTileFromWorldXY(x: number, y: number): number {
x = this._game.math.snapToFloor(x, this.tileWidth) / this.tileWidth;
@@ -180,6 +321,11 @@ module Phaser {
}
+ /**
+ * Get tiles overlaps the given object.
+ * @param object {GameObject} Tiles you want to get that overlaps this.
+ * @return {array} Array with tiles informations. (Each contains x, y and the tile.)
+ */
public getTileOverlaps(object: GameObject) {
// If the object is outside of the world coordinates then abort the check (tilemap has to exist within world bounds)
@@ -213,6 +359,14 @@ module Phaser {
}
+ /**
+ * Get a tile block with its position and size. (This method does not return, it'll set result to _tempTileBlock)
+ * @param x {number} X position of block's left-top corner.
+ * @param y {number} Y position of block's left-top corner.
+ * @param width {number} Width of block.
+ * @param height {number} Height of block.
+ * @param collisionOnly {boolean} Whethor or not ONLY return tiles which will collide (its allowCollisions value is not Collision.NONE).
+ */
private getTempBlock(x: number, y: number, width: number, height: number, collisionOnly?: bool = false) {
if (x < 0)
@@ -261,6 +415,12 @@ module Phaser {
}
+ /**
+ * Get the tile index of specific position (in tiles).
+ * @param x {number} X position of the tile.
+ * @param y {number} Y position of the tile.
+ * @return {number} Index of the tile at that position. Return null if there isn't a tile there.
+ */
public getTileIndex(x: number, y: number): number {
if (y >= 0 && y < this.mapData.length)
@@ -270,11 +430,15 @@ module Phaser {
return this.mapData[y][x];
}
}
-
+
return null;
}
+ /**
+ * Add a column of tiles into the layer.
+ * @param column {string[]/number[]} An array of tile indexes to be added.
+ */
public addColumn(column) {
var data = [];
@@ -297,12 +461,19 @@ module Phaser {
}
+ /**
+ * Update boundsInTiles with widthInTiles and heightInTiles.
+ */
public updateBounds() {
this.boundsInTiles.setTo(0, 0, this.widthInTiles, this.heightInTiles);
}
+ /**
+ * Parse tile offsets from map data.
+ * @return {number} length of _tileOffsets array.
+ */
public parseTileOffsets():number {
this._tileOffsets = [];
@@ -339,6 +510,13 @@ module Phaser {
}
+ /**
+ * Render this layer to a specific camera with offset to camera.
+ * @param camera {Camera} The camera the layer is going to be rendered.
+ * @param dx {number} X offset to the camera.
+ * @param dy {number} Y offset to the camera.
+ * @return {boolean} Return false if layer is invisible or has a too low opacity(will stop rendering), return true if succeed.
+ */
public render(camera: Camera, dx, dy): bool {
if (this.visible === false || this.alpha < 0.1)
@@ -430,7 +608,7 @@ module Phaser {
this.tileWidth, // Destination Width (always same as Source Width unless scaled)
this.tileHeight // Destination Height (always same as Source Height unless scaled)
);
-
+
}
this._tx += this.tileWidth;