Started revamp of the Tilemap system. Also removed old 'Advanced Physics' and dropped in p2.js which is what I hope we'll eventually use.

This commit is contained in:
photonstorm
2013-10-11 04:42:11 +01:00
parent a7230aa769
commit b868c2cb1b
72 changed files with 6704 additions and 6454 deletions
+80 -17
View File
@@ -56,6 +56,11 @@ Phaser.Cache = function (game) {
*/
this._tilemaps = {};
/**
* @property {object} _tilesets - Tileset key-value container.
* @private
*/
this._tilesets = {};
this.addDefaultImage();
@@ -118,6 +123,28 @@ Phaser.Cache.prototype = {
},
/**
* Add a new tile set in to the cache.
*
* @method Phaser.Cache#addTileset
* @param {string} key - The unique key by which you will reference this object.
* @param {string} url - URL of this tile set file.
* @param {object} data - Extra tile set data.
* @param {number} tileWidth - Width of the sprite sheet.
* @param {number} tileHeight - Height of the sprite sheet.
* @param {number} tileMax - How many tiles stored in the sprite sheet.
*/
addTileset: function (key, url, data, tileWidth, tileHeight, tileMax) {
this._tilesets[key] = { url: url, data: data, tileWidth: tileWidth, tileHeight: tileHeight };
PIXI.BaseTextureCache[key] = new PIXI.BaseTexture(data);
PIXI.TextureCache[key] = new PIXI.Texture(PIXI.BaseTextureCache[key]);
this._tilesets[key].tileData = Phaser.TilemapParser.tileset(this.game, key, tileWidth, tileHeight, tileMax);
},
/**
* Add a new tilemap.
*
@@ -208,6 +235,23 @@ Phaser.Cache.prototype = {
},
/**
* Add a new text data.
*
* @method Phaser.Cache#addText
* @param {string} key - Asset key for the text data.
* @param {string} url - URL of this text data file.
* @param {object} data - Extra text data.
*/
addText: function (key, url, data) {
this._text[key] = {
url: url,
data: data
};
},
/**
* Add a new image.
*
@@ -316,23 +360,6 @@ Phaser.Cache.prototype = {
this._sounds[key].decoded = true;
this._sounds[key].isDecoding = false;
},
/**
* Add a new text data.
*
* @method Phaser.Cache#addText
* @param {string} key - Asset key for the text data.
* @param {string} url - URL of this text data file.
* @param {object} data - Extra text data.
*/
addText: function (key, url, data) {
this._text[key] = {
url: url,
data: data
};
},
/**
@@ -387,6 +414,42 @@ Phaser.Cache.prototype = {
return null;
},
/**
* Get tile set image data by key.
*
* @method Phaser.Cache#getTileSetImage
* @param {string} key - Asset key of the image you want.
* @return {object} The image data you want.
*/
getTilesetImage: function (key) {
if (this._tilesets[key])
{
return this._tilesets[key].data;
}
return null;
},
/**
* Get tile set image data by key.
*
* @method Phaser.Cache#getTileset
* @param {string} key - Asset key of the image you want.
* @return {Phaser.Tileset} The tileset data. The tileset image is in the data property, the tile data in tileData.
*/
getTileset: function (key) {
if (this._tilesets[key])
{
return this._tilesets[key];
}
return null;
},
/**
* Get tilemap data by key.
*
+28 -1
View File
@@ -280,7 +280,7 @@ Phaser.Loader.prototype = {
* @param {string} url - URL of the sheet file.
* @param {number} frameWidth - Width of each single frame.
* @param {number} frameHeight - Height of each single frame.
* @param {number} frameMax - How many frames in this sprite sheet.
* @param {number} [frameMax=-1] - How many frames in this sprite sheet. If not specified it will divide the whole image into frames.
*/
spritesheet: function (key, url, frameWidth, frameHeight, frameMax) {
@@ -293,6 +293,27 @@ Phaser.Loader.prototype = {
},
/**
* Add a new tile set to the loader. These are used in the rendering of tile maps.
*
* @method Phaser.Loader#tileset
* @param {string} key - Unique asset key of the tileset file.
* @param {string} url - URL of the tileset.
* @param {number} tileWidth - Width of each single tile in pixels.
* @param {number} tileHeight - Height of each single tile in pixels.
* @param {number} [tileMax=-1] - How many tiles in this tileset. If not specified it will divide the whole image into tiles.
*/
tileset: function (key, url, tileWidth, tileHeight, tileMax) {
if (typeof tileMax === "undefined") { tileMax = -1; }
if (this.checkKeyExists(key) === false)
{
this.addToFileList('tileset', key, url, { tileWidth: tileWidth, tileHeight: tileHeight, tileMax: tileMax });
}
},
/**
* Add a new audio file to the loader.
*
@@ -617,6 +638,7 @@ Phaser.Loader.prototype = {
case 'textureatlas':
case 'bitmapfont':
case 'tilemap':
case 'tileset':
file.data = new Image();
file.data.name = file.key;
file.data.onload = function () {
@@ -771,6 +793,11 @@ Phaser.Loader.prototype = {
this.game.cache.addSpriteSheet(file.key, file.url, file.data, file.frameWidth, file.frameHeight, file.frameMax);
break;
case 'tileset':
this.game.cache.addTileset(file.key, file.url, file.data, file.tileWidth, file.tileHeight, file.tileMax);
break;
case 'tilemap':
if (file.mapDataURL == null)