Skip to content

Commit 61635c9

Browse files
committed
Added offsets to render large tiles at the correct (according to Tiled editor) positions.
1 parent b8c81c2 commit 61635c9

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

docs/_phaser_tilemap_GL_progress.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,14 @@ Tiles are still turning off too soon at the map edges (exactly like the Canvas v
172172

173173
Fixed tiles vanishing at the edge of the screen by using the difference between the original map tileWidth and the current tileset tileWidth when calculating the redraw region left and top.
174174

175-
176175
Removed resolveTileset from TilemapLayerGL as it is no longer needed.
177176

178177
Task list updated:
179178
- Add alpha blending to the shader, calculate the 'final' alpha by multiplying the layer's worldAlpha with the tile.alpha
180179
- Add scaling to the shader, use the layer's worldScale. (See if rotation can be easily supported too, while doing this)
181180
- Optimise the drawing to avoid degenerate triangles where possible, e.g. each row should be a single tri-strip without degenerates in it for faster drawing
182181
- larger tiles are top-left aligned but should be bottom-left aligned to match the way that Tiled places them
182+
183+
Added offset parameters to renderRegion to correctly bottom-left align the large tiles.
184+
NOTE: the canvas version does not do this and consequently displays the tiles in the wrong positions.
185+

src/tilemap/TilemapLayerGL.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ Phaser.TilemapLayerGL.prototype.setScale = function (xScale, yScale) {
638638
* @param {integer} right - Rightmost column to render.
639639
* @param {integer} bottom - Bottommost row to render.
640640
*/
641-
Phaser.TilemapLayerGL.prototype.renderRegion = function (scrollX, scrollY, left, top, right, bottom) {
641+
Phaser.TilemapLayerGL.prototype.renderRegion = function (scrollX, scrollY, left, top, right, bottom, offx, offy) {
642642

643643
var width = this.layer.width;
644644
var height = this.layer.height;
@@ -647,6 +647,9 @@ Phaser.TilemapLayerGL.prototype.renderRegion = function (scrollX, scrollY, left,
647647

648648
var lastAlpha = NaN;
649649

650+
offx = offx || 0;
651+
offy = offy || 0;
652+
650653
if (!this._wrap)
651654
{
652655
if (left <= right) // Only adjust if going to render
@@ -718,12 +721,12 @@ Phaser.TilemapLayerGL.prototype.renderRegion = function (scrollX, scrollY, left,
718721
// context.scale(-1, 1);
719722
// }
720723

721-
this._mc.tileset.drawGl(this.glBatch, -tile.centerX, -tile.centerY, index);
724+
this._mc.tileset.drawGl(this.glBatch, -tile.centerX + offx, -tile.centerY + offy, index);
722725
//context.restore();
723726
}
724727
else
725728
{
726-
this._mc.tileset.drawGl(this.glBatch, tx, ty, index);
729+
this._mc.tileset.drawGl(this.glBatch, tx + offx, ty + offy, index);
727730
}
728731
// if (!this._mc.tileset && this.debugSettings.missingImageFill)
729732
// {
@@ -765,11 +768,11 @@ Phaser.TilemapLayerGL.prototype.renderFull = function () {
765768

766769
var left = Math.floor( (scrollX - (cw - tw)) / tw );
767770
var right = Math.floor( (renderW - 1 + scrollX) / tw );
768-
var top = Math.floor( (scrollY - (ch - th)) / th );
771+
var top = Math.floor( scrollY - (ch - th) / th );
769772
var bottom = Math.floor( (renderH - 1 + scrollY) / th );
770773

771774
this.glBatch = [];
772-
this.renderRegion(scrollX, scrollY, left, top, right, bottom);
775+
this.renderRegion(scrollX, scrollY, left, top, right, bottom, 0, -(ch - th));
773776
};
774777

775778
/**

0 commit comments

Comments
 (0)