You can now create multiple blank layers in a Tilemap.

This commit is contained in:
photonstorm 2014-03-23 23:57:46 +00:00
parent 605414671e
commit e1c98ba617
5 changed files with 47 additions and 12 deletions

View file

@ -96,6 +96,7 @@ Bug Fixes
* The volume given in Sound.play now over-rides that set in Sound.addMarker if specified (fix #623)
* BitmapDatas when used as Game Object textures in WebGL now update themselves properly.
* Timer.ms now correctly reports the ms time even if the Timer has been paused (thanks Nambew, fix #624)
* If you added a Tileset to an empty map it would eventually throw an out of memory error.
Updated
@ -124,6 +125,7 @@ Updated
* ArcadePhysics.Body.setSize corrected to take the parameters as positive, not negative values.
* ArcadePhysics.World.seperate will now check gravity totals to determine separation order. You can set World.forceX to true to always separate on X first and skip this check.
* TileSprites now emit outOfBounds and enterBounds events accordingly.
* You can now create multiple blank layers in a Tilemap.
New Features

View file

@ -215,8 +215,8 @@ Phaser.Tilemap.prototype = {
* @method Phaser.Tilemap#addTilesetImage
* @param {string} tileset - The name of the tileset as specified in the map data.
* @param {string} [key] - The key of the Phaser.Cache image used for this tileset. If not specified it will look for an image with a key matching the tileset parameter.
* @param {number} [tileWidth] - The width of the tiles in the Tileset Image. If not given it will default to the map.tileWidth value.
* @param {number} [tileHeight] - The height of the tiles in the Tileset Image. If not given it will default to the map.tileHeight value.
* @param {number} [tileWidth=32] - The width of the tiles in the Tileset Image. If not given it will default to the map.tileWidth value, if that isn't set then 32.
* @param {number} [tileHeight=32] - The height of the tiles in the Tileset Image. If not given it will default to the map.tileHeight value, if that isn't set then 32.
* @param {number} [tileMargin=0] - The width of the tiles in the Tileset Image. If not given it will default to the map.tileWidth value.
* @param {number} [tileSpacing=0] - The height of the tiles in the Tileset Image. If not given it will default to the map.tileHeight value.
* @param {number} [gid=0] - If adding multiple tilesets to a blank/dynamic map, specify the starting GID the set will use here.
@ -230,6 +230,17 @@ Phaser.Tilemap.prototype = {
if (typeof tileSpacing === 'undefined') { tileSpacing = 0; }
if (typeof gid === 'undefined') { gid = 0; }
// In-case we're working from a blank map
if (tileWidth === 0)
{
tileWidth = 32;
}
if (tileHeight === 0)
{
tileHeight = 32;
}
if (typeof key === 'undefined')
{
if (typeof tileset === 'string')
@ -370,6 +381,7 @@ Phaser.Tilemap.prototype = {
* Creates a new TilemapLayer object. By default TilemapLayers are fixed to the camera.
* The `layer` parameter is important. If you've created your map in Tiled then you can get this by looking in Tiled and looking at the Layer name.
* Or you can open the JSON file it exports and look at the layers[].name value. Either way it must match.
* If you wish to create a blank layer to put your own tiles on then see Tilemap.createBlankLayer.
*
* @method Phaser.Tilemap#createLayer
* @param {number|string} layer - The layer array index value, or if a string is given the layer name, within the map data that this TilemapLayer represents.
@ -463,7 +475,23 @@ Phaser.Tilemap.prototype = {
this.currentLayer = this.layers.length - 1;
return group.add(new Phaser.TilemapLayer(this.game, this, this.layers.length - 1, layer.widthInPixels, layer.heightInPixels));
var w = layer.widthInPixels;
var h = layer.heightInPixels;
if (w > this.game.width)
{
w = this.game.width;
}
if (h > this.game.height)
{
h = this.game.height;
}
var output = new Phaser.TilemapLayer(this.game, this, this.layers.length - 1, w, h);
output.name = name;
return group.add(output);
},

View file

@ -206,7 +206,9 @@ Phaser.TilemapLayer.prototype.constructor = Phaser.TilemapLayer;
*/
Phaser.TilemapLayer.prototype.postUpdate = function () {
// Phaser.Image.prototype.postUpdate.call(this);
// console.log('layer pu');
Phaser.Image.prototype.postUpdate.call(this);
// Stops you being able to auto-scroll the camera if it's not following a sprite
this.scrollX = this.game.camera.x * this.scrollFactorX;
@ -685,7 +687,6 @@ Object.defineProperty(Phaser.TilemapLayer.prototype, "scrollX", {
set: function (value) {
// if (value !== this.cache.x && value >= 0 && this.layer && this.layer.widthInPixels > this.width)
if (value !== this.cache.x && value >= 0 && this.layer.widthInPixels > this.width)
{
this.cache.x = value;
@ -726,7 +727,6 @@ Object.defineProperty(Phaser.TilemapLayer.prototype, "scrollY", {
set: function (value) {
// if (value !== this.cache.y && value >= 0 && this.layer && this.heightInPixels > this.renderHeight)
if (value !== this.cache.y && value >= 0 && this.layer.heightInPixels > this.height)
{
this.cache.y = value;

View file

@ -12,14 +12,19 @@
* @constructor
* @param {string} name - The name of the tileset in the map data.
* @param {number} firstgid - The Tiled firstgid value. In non-Tiled data this should be considered the starting index value of the first tile in this set.
* @param {number} width - Width of each tile in pixels.
* @param {number} height - Height of each tile in pixels.
* @param {number} margin - The amount of margin around the tilesheet.
* @param {number} spacing - The amount of spacing between each tile in the sheet.
* @param {object} properties - Tileset properties.
* @param {number} [width=32] - Width of each tile in pixels.
* @param {number} [height=32] - Height of each tile in pixels.
* @param {number} [margin=0] - The amount of margin around the tilesheet.
* @param {number} [spacing=0] - The amount of spacing between each tile in the sheet.
* @param {object} [properties] - Tileset properties.
*/
Phaser.Tileset = function (name, firstgid, width, height, margin, spacing, properties) {
if (typeof width === 'undefined' || width <= 0) { width = 32; }
if (typeof height === 'undefined' || height <= 0) { height = 32; }
if (typeof margin === 'undefined') { margin = 0; }
if (typeof spacing === 'undefined') { spacing = 0; }
/**
* @property {string} name - The name of the Tileset.
*/

View file

@ -199,7 +199,7 @@ Phaser.Tween.prototype = {
* @param {function} [ease=null] - Easing function. If not set it will default to Phaser.Easing.Linear.None.
* @param {boolean} [autoStart=false] - Whether this tween will start automatically or not.
* @param {number} [delay=0] - Delay before this tween will start, defaults to 0 (no delay). Value given is in ms.
* @param {boolean} [repeat=0] - Should the tween automatically restart once complete? (ignores any chained tweens).
* @param {number} [repeat=0] - Should the tween automatically restart once complete? If you want it to run forever set as Number.MAX_VALUE. This ignores any chained tweens.
* @param {boolean} [yoyo=false] - A tween that yoyos will reverse itself when it completes.
* @return {Phaser.Tween} This Tween object.
*/