Skip to content

Commit

Permalink
[#105] Fix TMXOrthogonalRenderer with tile size delta between map and…
Browse files Browse the repository at this point in the history
… tileset

- See platformer2 for an example; this bug appears while scrolling
  • Loading branch information
parasyte committed Sep 6, 2015
1 parent 0dd47ae commit 4eb3454
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
12 changes: 12 additions & 0 deletions src/level/TMXLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,20 @@
this.tilesets = tilesets;

// the default tileset
// XXX: Is this even used?
this.tileset = (this.tilesets ? this.tilesets.getTilesetByIndex(0) : null);

// Biggest tile size to draw
this.maxTileSize = {
"width" : 0,
"height" : 0
};
for (var i = 0; i < this.tilesets.length; i++) {
var tileset = this.tilesets.getTilesetByIndex(i);
this.maxTileSize.width = Math.max(this.maxTileSize.width, tileset.tilewidth);
this.maxTileSize.height = Math.max(this.maxTileSize.height, tileset.tileheight);
}

/**
* All animated tilesets in this layer
* @private
Expand Down
4 changes: 2 additions & 2 deletions src/level/TMXRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@
drawTileLayer : function (renderer, layer, rect) {
// get top-left and bottom-right tile position
var start = this.pixelToTileCoords(
rect.pos.x,
rect.pos.y,
Math.max(rect.pos.x - (layer.maxTileSize.width - layer.tilewidth), 0),
Math.max(rect.pos.y - (layer.maxTileSize.height - layer.tileheight), 0),
me.pool.pull("me.Vector2d")
).floorSelf();

Expand Down
4 changes: 3 additions & 1 deletion src/level/TMXTileset.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,13 @@
// constructor
init: function () {
this.tilesets = [];
this.length = 0;
},

//add a tileset to the tileset group
add : function (tileset) {
this.tilesets.push(tileset);
this.length++;
},

//return the tileset at the specified index
Expand All @@ -260,7 +262,7 @@

// clear the gid of all flip/rotation flags
gid &= TMX_CLEAR_BIT_MASK;

// cycle through all tilesets
for (var i = 0, len = this.tilesets.length; i < len; i++) {
// return the corresponding tileset if matching
Expand Down

0 comments on commit 4eb3454

Please sign in to comment.