diff --git a/README.md b/README.md index 3e5eb6758..830e7d53a 100644 --- a/README.md +++ b/README.md @@ -325,6 +325,7 @@ You can read all about the philosophy behind Lazer [here](http://phaser.io/news/ * Group.align now returns `true` if the Group was aligned, or `false` if not. * The Loader.headers object has a new property `requestedWith`. By default this is set to `false`, but it can be used to set the `X-Requested-With` header to `XMLHttpRequest` (or any other value you need). To enable this do `this.load.headers.requestedWith = 'XMLHttpRequest'` before adding anything to the Loader. * ScaleManager.hasPhaserSetFullScreen is a new boolean that identifies if the browser is in full screen mode or not, and if Phaser was the one that requested it. As it's possible to enter full screen mode outside of Phaser, and it then gets confused about what bounding parent to use. +* Phaser.Tileset has a new property `lastgid` which is populated automatically by the TilemapParser when importing Tiled map data, or can be set manually if building your own tileset. ### Bug Fixes diff --git a/src/tilemap/TilemapParser.js b/src/tilemap/TilemapParser.js index 6e118bb64..541393ee0 100644 --- a/src/tilemap/TilemapParser.js +++ b/src/tilemap/TilemapParser.js @@ -353,14 +353,17 @@ Phaser.TilemapParser = { if (gid > 0) { var tile = new Phaser.Tile(layer, gid, x, output.length, json.tilewidth, json.tileheight); + tile.rotation = rotation; tile.flipped = flipped; - if ( flippedVal !== 0 ) + + if (flippedVal !== 0) { - // the webgl renderer uses this to flip UV coordinates before drawing + // The WebGL renderer uses this to flip UV coordinates before drawing tile.flippedVal = flippedVal; } - row.push( tile ); + + row.push(tile); } else { @@ -429,6 +432,7 @@ Phaser.TilemapParser = { // Tilesets & Image Collections var tilesets = []; var imagecollections = []; + var lastSet = null; for (var i = 0; i < json.tilesets.length; i++) { @@ -447,6 +451,7 @@ Phaser.TilemapParser = { // For a normal sliced tileset the row/count/size information is computed when updated. // This is done (again) after the image is set. newSet.updateTileData(set.imagewidth, set.imageheight); + tilesets.push(newSet); } else @@ -463,6 +468,13 @@ Phaser.TilemapParser = { imagecollections.push(newCollection); } + // We've got a new Tileset, so set the lastgid into the previous one + if (lastSet) + { + lastSet.lastgid = set.firstgid - 1; + } + + lastSet = set; } map.tilesets = tilesets; diff --git a/src/tilemap/Tileset.js b/src/tilemap/Tileset.js index 91b7b8138..3849e8654 100644 --- a/src/tilemap/Tileset.js +++ b/src/tilemap/Tileset.js @@ -39,6 +39,14 @@ Phaser.Tileset = function (name, firstgid, width, height, margin, spacing, prope */ this.firstgid = firstgid | 0; + /** + * This is the ending index of the last tile index this Tileset can contain. + * This is populated automatically by Phaser.TilemapParser.parseTiledJSON. + * For a single tileset map it should be left as the default value. + * @property {integer} lastgid + */ + this.lastgid = Infinity; + /** * The width of each tile (in pixels). * @property {integer} tileWidth @@ -154,10 +162,10 @@ Phaser.Tileset.prototype = { }, /** - * Draws a tile from this Tileset at the given coordinates using a WebGL renderer. + * Sets the GL Batch data to draw a tile from this Tileset at the given coordinates + * using a WebGL renderer. * * @method Phaser.Tileset#drawGl - * @public * @param {Array} glBatch - A list of WebGL batch objects to draw later. * @param {number} x - The x coordinate to draw to. * @param {number} y - The y coordinate to draw to. @@ -222,15 +230,15 @@ Phaser.Tileset.prototype = { }, /** - * Adds a marker for the WebGl batch display to insert a degenerate triangle (eg. at the end of each row of tiles) + * Adds a marker for the WebGL batch display to insert a degenerate + * triangle (eg. at the end of each row of tiles) * * @method Phaser.Tileset#addDegenerate - * @public - * @param {[type]} glBatch [description] + * @param {array} glBatch - The GL Batch data array. */ addDegenerate: function (glBatch) { - // don't insert multiple degenerate markers in a row + // Don't insert multiple degenerate markers in a row if (glBatch[glBatch.length - 1]) { glBatch.push(null); diff --git a/typescript/phaser.d.ts b/typescript/phaser.d.ts index 117bedf4b..17997f7ac 100644 --- a/typescript/phaser.d.ts +++ b/typescript/phaser.d.ts @@ -5164,6 +5164,7 @@ declare module Phaser { columns: number; firstgid: number; image: any; + lastgid: number; name: string; properties: any; rows: number; @@ -5175,6 +5176,7 @@ declare module Phaser { containsTileIndex(tileIndex: number): boolean; draw(context: CanvasRenderingContext2D, x: number, y: number, index: number): void; + drawGl(glBatch: any[], x: number, y: number, index: number, alpha: number, flippedVal: number): void; setImage(image: any): void; setSpacing(margin?: number, spacing?: number): void;