diff --git a/README.md b/README.md index 33d4c9b71..616a3c13d 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/tilemap/Tilemap.js b/src/tilemap/Tilemap.js index d53d37ebf..8084510f4 100644 --- a/src/tilemap/Tilemap.js +++ b/src/tilemap/Tilemap.js @@ -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); }, diff --git a/src/tilemap/TilemapLayer.js b/src/tilemap/TilemapLayer.js index e08f390b4..d18ba71bf 100644 --- a/src/tilemap/TilemapLayer.js +++ b/src/tilemap/TilemapLayer.js @@ -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; diff --git a/src/tilemap/Tileset.js b/src/tilemap/Tileset.js index 1ddb96e1d..a8659f154 100644 --- a/src/tilemap/Tileset.js +++ b/src/tilemap/Tileset.js @@ -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. */ diff --git a/src/tween/Tween.js b/src/tween/Tween.js index e598ffced..6b388f5ee 100644 --- a/src/tween/Tween.js +++ b/src/tween/Tween.js @@ -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. */