Finish document for ScrollRegion, ScrollZone, Tilemap, Device, TilemapLayer.

This commit is contained in:
Sean
2013-05-10 16:31:16 +01:00
committed by Richard Davey
parent 00ef200914
commit ca932038fb
5 changed files with 576 additions and 174 deletions
+130 -169
View File
@@ -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 = '';
+180 -2
View File
@@ -10,6 +10,18 @@ module Phaser {
export class TilemapLayer {
/**
* TilemapLayer constructor
* Create a new <code>TilemapLayer</code>.
*
* @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;