From 35a04b2f1ef2fd7e2ffd20c9c88ac1d286bd916c Mon Sep 17 00:00:00 2001 From: photonstorm Date: Sun, 8 Feb 2015 23:25:41 +0000 Subject: [PATCH] TilemapParser now supports Tiled 0.11 version maps which includes the `rotation` property on all Object types. Tilemap.createFromObjects now checks for a `rotation` property on the Object and if present will set it as the Sprite.angle (#1433) --- README.md | 4 ++- src/tilemap/Tilemap.js | 5 +++ src/tilemap/TilemapParser.js | 61 ++++++++++++++++++++++++++---------- 3 files changed, 53 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index e94177fb9..caae9a09d 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,8 @@ Version 2.3.0 - "Tarabon" - in dev * MSPointer.pointerDownCallback, pointerMoveCallback and pointerUpCallback all allow you to set your own event based callbacks. * MSPointer.button now records which button was pressed down (if any) * Phaser now supports rotated and flipped tiles in tilemaps, as exported from the Tiled map editor (thanks @nkholski #1608) - +* TilemapParser now supports Tiled 0.11 version maps which includes the `rotation` property on all Object types. +* Tilemap.createFromObjects now checks for a `rotation` property on the Object and if present will set it as the Sprite.angle (#1433) ### Updates @@ -102,6 +103,7 @@ Version 2.3.0 - "Tarabon" - in dev * TileSprites weren't destroying WebGL textures, leading to eventual out of memory errors (thanks @chacal #1563) * P2.Body.clearCollision default values were incorrectly set to `false` if no parameters were provided, even though the docs said they were `true` (thanks @brianbunch #1597) * BitmapText.font wouldn't update an internal Pixi property (fontName) causing the text to fail to change font (thanks @starnut #1602) +* Fixed issue in PIXI.Text where it was using the wrong string for descender text measurements. For changes in previous releases please see the extensive [Version History](https://github.com/photonstorm/phaser/blob/master/CHANGELOG.md). diff --git a/src/tilemap/Tilemap.js b/src/tilemap/Tilemap.js index 70254f1d1..d19815be5 100644 --- a/src/tilemap/Tilemap.js +++ b/src/tilemap/Tilemap.js @@ -402,6 +402,11 @@ Phaser.Tilemap.prototype = { sprite.autoCull = autoCull; sprite.exists = exists; + if (this.objects[name][i].rotation) + { + sprite.angle = this.objects[name][i].rotation; + } + if (adjustY) { sprite.y -= sprite.height; diff --git a/src/tilemap/TilemapParser.js b/src/tilemap/TilemapParser.js index 3cd129f46..1b812042c 100644 --- a/src/tilemap/TilemapParser.js +++ b/src/tilemap/TilemapParser.js @@ -256,23 +256,31 @@ Phaser.TilemapParser = { rotation = 0; flipped = false; gid = json.layers[i].data[t]; - if (gid > 0x20000000) // if true the current tile is flipped or rotated (Tiled TMX format) + + // If true the current tile is flipped or rotated (Tiled TMX format) + if (gid > 0x20000000) { - flippedVal=0; - if(gid>0x80000000) // FlippedX + flippedVal = 0; + + // FlippedX + if (gid > 0x80000000) { - gid-=0x80000000; - flippedVal+=4; + gid -= 0x80000000; + flippedVal += 4; } - if(gid>0x40000000) // FlippedY + + // FlippedY + if (gid > 0x40000000) { - gid-=0x40000000; - flippedVal+=2; + gid -= 0x40000000; + flippedVal += 2; } - if(gid>0x20000000) // FlippedAD + + // FlippedAD + if (gid > 0x20000000) { - gid-=0x20000000; - flippedVal+=1; + gid -= 0x20000000; + flippedVal += 1; } switch (flippedVal) @@ -304,6 +312,7 @@ Phaser.TilemapParser = { break; } } + // index, x, y, width, height if (gid > 0) { @@ -404,11 +413,19 @@ Phaser.TilemapParser = { var collision = {}; function slice (obj, fields) { + var sliced = {}; - for (var k in fields) { + + for (var k in fields) + { var key = fields[k]; - sliced[key] = obj[key]; + + if (obj[key]) + { + sliced[key] = obj[key]; + } } + return sliced; } @@ -438,6 +455,11 @@ Phaser.TilemapParser = { }; + if (json.layers[i].objects[v].rotation) + { + object.rotation = json.layers[i].objects[v].rotation; + } + objects[json.layers[i].name].push(object); } else if (json.layers[i].objects[v].polyline) @@ -455,6 +477,11 @@ Phaser.TilemapParser = { }; + if (json.layers[i].objects[v].rotation) + { + object.rotation = json.layers[i].objects[v].rotation; + } + object.polyline = []; // Parse the polyline into an array @@ -470,14 +497,16 @@ Phaser.TilemapParser = { else if (json.layers[i].objects[v].polygon) { var object = slice(json.layers[i].objects[v], - ["name", "type", "x", "y", "visible", "properties" ]); + ["name", "type", "x", "y", "visible", "rotation", "properties" ]); // Parse the polygon into an array object.polygon = []; + for (var p = 0; p < json.layers[i].objects[v].polygon.length; p++) { object.polygon.push([ json.layers[i].objects[v].polygon[p].x, json.layers[i].objects[v].polygon[p].y ]); } + objects[json.layers[i].name].push(object); } @@ -485,14 +514,14 @@ Phaser.TilemapParser = { else if (json.layers[i].objects[v].ellipse) { var object = slice(json.layers[i].objects[v], - ["name", "type", "ellipse", "x", "y", "width", "height", "visible", "properties" ]); + ["name", "type", "ellipse", "x", "y", "width", "height", "visible", "rotation", "properties" ]); objects[json.layers[i].name].push(object); } // otherwise it's a rectangle else { var object = slice(json.layers[i].objects[v], - ["name", "type", "x", "y", "width", "height", "visible", "properties" ]); + ["name", "type", "x", "y", "width", "height", "visible", "rotation", "properties" ]); object.rectangle = true; objects[json.layers[i].name].push(object); }