Skip to content

Commit e1c98ba

Browse files
committed
You can now create multiple blank layers in a Tilemap.
1 parent 6054146 commit e1c98ba

5 files changed

Lines changed: 47 additions & 12 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ Bug Fixes
9696
* The volume given in Sound.play now over-rides that set in Sound.addMarker if specified (fix #623)
9797
* BitmapDatas when used as Game Object textures in WebGL now update themselves properly.
9898
* Timer.ms now correctly reports the ms time even if the Timer has been paused (thanks Nambew, fix #624)
99+
* If you added a Tileset to an empty map it would eventually throw an out of memory error.
99100

100101

101102
Updated
@@ -124,6 +125,7 @@ Updated
124125
* ArcadePhysics.Body.setSize corrected to take the parameters as positive, not negative values.
125126
* 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.
126127
* TileSprites now emit outOfBounds and enterBounds events accordingly.
128+
* You can now create multiple blank layers in a Tilemap.
127129

128130

129131
New Features

src/tilemap/Tilemap.js

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,8 @@ Phaser.Tilemap.prototype = {
215215
* @method Phaser.Tilemap#addTilesetImage
216216
* @param {string} tileset - The name of the tileset as specified in the map data.
217217
* @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.
218-
* @param {number} [tileWidth] - The width of the tiles in the Tileset Image. If not given it will default to the map.tileWidth value.
219-
* @param {number} [tileHeight] - The height of the tiles in the Tileset Image. If not given it will default to the map.tileHeight value.
218+
* @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.
219+
* @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.
220220
* @param {number} [tileMargin=0] - The width of the tiles in the Tileset Image. If not given it will default to the map.tileWidth value.
221221
* @param {number} [tileSpacing=0] - The height of the tiles in the Tileset Image. If not given it will default to the map.tileHeight value.
222222
* @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 = {
230230
if (typeof tileSpacing === 'undefined') { tileSpacing = 0; }
231231
if (typeof gid === 'undefined') { gid = 0; }
232232

233+
// In-case we're working from a blank map
234+
if (tileWidth === 0)
235+
{
236+
tileWidth = 32;
237+
}
238+
239+
if (tileHeight === 0)
240+
{
241+
tileHeight = 32;
242+
}
243+
233244
if (typeof key === 'undefined')
234245
{
235246
if (typeof tileset === 'string')
@@ -370,6 +381,7 @@ Phaser.Tilemap.prototype = {
370381
* Creates a new TilemapLayer object. By default TilemapLayers are fixed to the camera.
371382
* 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.
372383
* Or you can open the JSON file it exports and look at the layers[].name value. Either way it must match.
384+
* If you wish to create a blank layer to put your own tiles on then see Tilemap.createBlankLayer.
373385
*
374386
* @method Phaser.Tilemap#createLayer
375387
* @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 = {
463475

464476
this.currentLayer = this.layers.length - 1;
465477

466-
return group.add(new Phaser.TilemapLayer(this.game, this, this.layers.length - 1, layer.widthInPixels, layer.heightInPixels));
478+
var w = layer.widthInPixels;
479+
var h = layer.heightInPixels;
480+
481+
if (w > this.game.width)
482+
{
483+
w = this.game.width;
484+
}
485+
486+
if (h > this.game.height)
487+
{
488+
h = this.game.height;
489+
}
490+
491+
var output = new Phaser.TilemapLayer(this.game, this, this.layers.length - 1, w, h);
492+
output.name = name;
493+
494+
return group.add(output);
467495

468496
},
469497

src/tilemap/TilemapLayer.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,9 @@ Phaser.TilemapLayer.prototype.constructor = Phaser.TilemapLayer;
206206
*/
207207
Phaser.TilemapLayer.prototype.postUpdate = function () {
208208

209-
// Phaser.Image.prototype.postUpdate.call(this);
209+
// console.log('layer pu');
210+
211+
Phaser.Image.prototype.postUpdate.call(this);
210212

211213
// Stops you being able to auto-scroll the camera if it's not following a sprite
212214
this.scrollX = this.game.camera.x * this.scrollFactorX;
@@ -685,7 +687,6 @@ Object.defineProperty(Phaser.TilemapLayer.prototype, "scrollX", {
685687

686688
set: function (value) {
687689

688-
// if (value !== this.cache.x && value >= 0 && this.layer && this.layer.widthInPixels > this.width)
689690
if (value !== this.cache.x && value >= 0 && this.layer.widthInPixels > this.width)
690691
{
691692
this.cache.x = value;
@@ -726,7 +727,6 @@ Object.defineProperty(Phaser.TilemapLayer.prototype, "scrollY", {
726727

727728
set: function (value) {
728729

729-
// if (value !== this.cache.y && value >= 0 && this.layer && this.heightInPixels > this.renderHeight)
730730
if (value !== this.cache.y && value >= 0 && this.layer.heightInPixels > this.height)
731731
{
732732
this.cache.y = value;

src/tilemap/Tileset.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,19 @@
1212
* @constructor
1313
* @param {string} name - The name of the tileset in the map data.
1414
* @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.
15-
* @param {number} width - Width of each tile in pixels.
16-
* @param {number} height - Height of each tile in pixels.
17-
* @param {number} margin - The amount of margin around the tilesheet.
18-
* @param {number} spacing - The amount of spacing between each tile in the sheet.
19-
* @param {object} properties - Tileset properties.
15+
* @param {number} [width=32] - Width of each tile in pixels.
16+
* @param {number} [height=32] - Height of each tile in pixels.
17+
* @param {number} [margin=0] - The amount of margin around the tilesheet.
18+
* @param {number} [spacing=0] - The amount of spacing between each tile in the sheet.
19+
* @param {object} [properties] - Tileset properties.
2020
*/
2121
Phaser.Tileset = function (name, firstgid, width, height, margin, spacing, properties) {
2222

23+
if (typeof width === 'undefined' || width <= 0) { width = 32; }
24+
if (typeof height === 'undefined' || height <= 0) { height = 32; }
25+
if (typeof margin === 'undefined') { margin = 0; }
26+
if (typeof spacing === 'undefined') { spacing = 0; }
27+
2328
/**
2429
* @property {string} name - The name of the Tileset.
2530
*/

src/tween/Tween.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ Phaser.Tween.prototype = {
199199
* @param {function} [ease=null] - Easing function. If not set it will default to Phaser.Easing.Linear.None.
200200
* @param {boolean} [autoStart=false] - Whether this tween will start automatically or not.
201201
* @param {number} [delay=0] - Delay before this tween will start, defaults to 0 (no delay). Value given is in ms.
202-
* @param {boolean} [repeat=0] - Should the tween automatically restart once complete? (ignores any chained tweens).
202+
* @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.
203203
* @param {boolean} [yoyo=false] - A tween that yoyos will reverse itself when it completes.
204204
* @return {Phaser.Tween} This Tween object.
205205
*/

0 commit comments

Comments
 (0)