Skip to content

Commit b8c81c2

Browse files
committed
Removed resolveTileset from TilemapLayerGL, added new task to task list.
1 parent 20b3d92 commit b8c81c2

2 files changed

Lines changed: 26 additions & 59 deletions

File tree

docs/_phaser_tilemap_GL_progress.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,13 @@ Made TilemapLayerGL grab the tile dimensions from the new tileset parameter inst
170170
First working demo with multiple webgl layers each batching tiles from separate tilesets which were all attached to one map layer in the Tiled program.
171171
Tiles are still turning off too soon at the map edges (exactly like the Canvas version) but that should be fixable with this 'internal layer' approach.
172172

173+
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.
174+
175+
176+
Removed resolveTileset from TilemapLayerGL as it is no longer needed.
177+
178+
Task list updated:
179+
- Add alpha blending to the shader, calculate the 'final' alpha by multiplying the layer's worldAlpha with the tile.alpha
180+
- Add scaling to the shader, use the layer's worldScale. (See if rotation can be easily supported too, while doing this)
181+
- 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
182+
- larger tiles are top-left aligned but should be bottom-left aligned to match the way that Tiled places them

src/tilemap/TilemapLayerGL.js

Lines changed: 16 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ Phaser.TilemapLayerGL = function (game, tilemap, index, width, height) {
171171
* @property {object} _mc
172172
* @private
173173
*/
174-
var tileset = this.layer.tileset || this.map.tilesets[0];
174+
var tileset = this.layer.tileset || this.map.tilesets[0];
175175
this._mc = {
176176

177177
// Used to bypass rendering without reliance on `dirty` and detect changes.
@@ -580,44 +580,6 @@ Phaser.TilemapLayerGL.prototype.getTiles = function (x, y, width, height, collid
580580

581581
};
582582

583-
/**
584-
* Returns the appropriate tileset for the index, updating the internal cache as required.
585-
* This should only be called if `tilesets[index]` evaluates to undefined.
586-
*
587-
* @method Phaser.TilemapLayerGL#resolveTileset
588-
* @private
589-
* @param {integer} Tile index
590-
* @return {Phaser.Tileset|null} Returns the associated tileset or null if there is no such mapping.
591-
*/
592-
Phaser.TilemapLayerGL.prototype.resolveTileset = function (tileIndex) {
593-
594-
var tilesets = this._mc.tilesets;
595-
596-
// Try for dense array if reasonable
597-
if (tileIndex < 2000)
598-
{
599-
while (tilesets.length < tileIndex)
600-
{
601-
tilesets.push(undefined);
602-
}
603-
}
604-
605-
var setIndex = this.map.tiles[tileIndex] && this.map.tiles[tileIndex][2];
606-
607-
if (setIndex != null) // number: not null or undefined
608-
{
609-
var tileset = this.map.tilesets[setIndex];
610-
611-
if (tileset && tileset.containsTileIndex(tileIndex))
612-
{
613-
return (tilesets[tileIndex] = tileset);
614-
}
615-
}
616-
617-
return (tilesets[tileIndex] = null);
618-
619-
};
620-
621583
/**
622584
* The TilemapLayerGL caches tileset look-ups.
623585
*
@@ -739,36 +701,31 @@ Phaser.TilemapLayerGL.prototype.renderRegion = function (scrollX, scrollY, left,
739701

740702
var index = tile.index;
741703

742-
var set = this.resolveTileset(index);
743-
744704
if (tile.alpha !== lastAlpha && !this.debug)
745705
{
746706
//context.globalAlpha = tile.alpha;
747707
lastAlpha = tile.alpha;
748708
}
749709

750-
if (set)
710+
if (tile.rotation || tile.flipped)
751711
{
752-
if (tile.rotation || tile.flipped)
753-
{
754-
//context.save();
755-
//context.translate(tx + tile.centerX, ty + tile.centerY);
756-
//context.rotate(tile.rotation);
712+
//context.save();
713+
//context.translate(tx + tile.centerX, ty + tile.centerY);
714+
//context.rotate(tile.rotation);
757715

758-
// if (tile.flipped)
759-
// {
760-
// context.scale(-1, 1);
761-
// }
716+
// if (tile.flipped)
717+
// {
718+
// context.scale(-1, 1);
719+
// }
762720

763-
set.drawGl(this.glBatch, -tile.centerX, -tile.centerY, index);
764-
//context.restore();
765-
}
766-
else
767-
{
768-
set.drawGl(this.glBatch, tx, ty, index);
769-
}
721+
this._mc.tileset.drawGl(this.glBatch, -tile.centerX, -tile.centerY, index);
722+
//context.restore();
723+
}
724+
else
725+
{
726+
this._mc.tileset.drawGl(this.glBatch, tx, ty, index);
770727
}
771-
// else if (this.debugSettings.missingImageFill)
728+
// if (!this._mc.tileset && this.debugSettings.missingImageFill)
772729
// {
773730
// context.fillStyle = this.debugSettings.missingImageFill;
774731
// context.fillRect(tx, ty, tw, th);

0 commit comments

Comments
 (0)