Skip to content

Commit

Permalink
fix #25; properly handle flipped tiles
Browse files Browse the repository at this point in the history
  • Loading branch information
englercj committed Feb 9, 2015
1 parent d74babe commit 60327c1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/tiled/Objectlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,12 @@ Objectlayer.prototype.spawn = function (spawnCallback) {
if (props.tileprops) {
if (props.tileprops.flippedX) {
obj.scale.x = -1;
obj.position.x += Math.abs(obj.width);
}

if (props.tileprops.flippedY) {
obj.scale.y = -1;
obj.position.y += Math.abs(obj.height);
}

// from Tiled Editor:
Expand All @@ -227,7 +229,7 @@ Objectlayer.prototype.spawn = function (spawnCallback) {
obj.scale.x = obj.scale.y;
obj.scale.y = sx;

var halfDiff = (o.height / 2) - (o.width / 2);
var halfDiff = Math.abs(o.height / 2) - Math.abs(o.width / 2);
obj.position.y += halfDiff;
obj.position.x += halfDiff;
}
Expand Down
4 changes: 3 additions & 1 deletion src/tiled/Tile.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,12 @@ function Tile(game, x, y, tileId, tileset, layer) {
// setup the flipped states
if (this.properties.flippedX) {
this.scale.x = -1;
this.position.x += tileset.tileWidth;
}

if (this.properties.flippedY) {
this.scale.y = -1;
this.position.y += tileset.tileHeight;
}

// from Tiled Editor:
Expand All @@ -140,7 +142,7 @@ function Tile(game, x, y, tileId, tileset, layer) {
this.scale.x = this.scale.y;
this.scale.y = sx;

var halfDiff = (this.height / 2) - (this.width / 2);
var halfDiff = Math.abs(this.height / 2) - Math.abs(this.width / 2);
this.position.y += halfDiff;
this.position.x += halfDiff;
}
Expand Down

0 comments on commit 60327c1

Please sign in to comment.