Skip to content

Commit 20b3d92

Browse files
committed
Fixed large tiles vanishing at screen edges by making a clear distinction between the original tilemap tile width and height, and the collision width and height of tiles for each layer. The difference between these two is now applied when calculating the region to be drawn to fill the screen.
1 parent 4f1728c commit 20b3d92

1 file changed

Lines changed: 18 additions & 11 deletions

File tree

src/tilemap/TilemapLayerGL.js

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +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];
174175
this._mc = {
175176

176177
// Used to bypass rendering without reliance on `dirty` and detect changes.
@@ -179,18 +180,23 @@ Phaser.TilemapLayerGL = function (game, tilemap, index, width, height) {
179180
renderWidth: 0,
180181
renderHeight: 0,
181182

183+
// dimensions of tiles in the original tilemap (the one holding all the tile indices)
182184
tileWidth: tilemap.tileWidth,
183185
tileHeight: tilemap.tileHeight,
184186

185187
// Collision width/height (pixels)
186188
// What purpose do these have? Most things use tile width/height directly.
187-
// This also only extends collisions right and down.
188-
cw: tilemap.tileWidth,
189-
ch: tilemap.tileHeight,
189+
// This also only extends collisions right and down.
190+
191+
// dimensions of tiles in this tileset (may not match the original tilemap)
192+
cw: tileset.tileWidth,
193+
ch: tileset.tileHeight,
194+
195+
// the tileset for this layer
196+
tileset: tileset,
190197

191198
// Cached tilesets from index -> Tileset
192199
tilesets: []
193-
194200
};
195201

196202
/**
@@ -223,9 +229,8 @@ Phaser.TilemapLayerGL = function (game, tilemap, index, width, height) {
223229
this._results = [];
224230

225231
// get PIXI textures for each tileset source image
226-
var tileset = this.layer.tileset || this.map.tilesets[0];
227232
var baseTexture = new PIXI.BaseTexture( tileset.image );
228-
PIXI.Tilemap.call(this, new PIXI.Texture(baseTexture), this.map.width, this.map.height, tileset.tileWidth, tileset.tileHeight, this.layer);
233+
PIXI.Tilemap.call(this, new PIXI.Texture(baseTexture), this.map.width, this.map.height, this._mc.tileset.tileWidth, this._mc.tileset.tileHeight, this.layer);
229234

230235
Phaser.Component.Core.init.call(this, game, 0, 0, null, null);
231236

@@ -678,7 +683,6 @@ Phaser.TilemapLayerGL.prototype.renderRegion = function (scrollX, scrollY, left,
678683
var tw = this._mc.tileWidth;
679684
var th = this._mc.tileHeight;
680685

681-
var tilesets = this._mc.tilesets;
682686
var lastAlpha = NaN;
683687

684688
if (!this._wrap)
@@ -799,10 +803,13 @@ Phaser.TilemapLayerGL.prototype.renderFull = function () {
799803
var tw = this._mc.tileWidth;
800804
var th = this._mc.tileHeight;
801805

802-
var left = Math.floor(scrollX / tw);
803-
var right = Math.floor((renderW - 1 + scrollX) / tw);
804-
var top = Math.floor(scrollY / th);
805-
var bottom = Math.floor((renderH - 1 + scrollY) / th);
806+
var cw = this._mc.cw;
807+
var ch = this._mc.ch;
808+
809+
var left = Math.floor( (scrollX - (cw - tw)) / tw );
810+
var right = Math.floor( (renderW - 1 + scrollX) / tw );
811+
var top = Math.floor( (scrollY - (ch - th)) / th );
812+
var bottom = Math.floor( (renderH - 1 + scrollY) / th );
806813

807814
this.glBatch = [];
808815
this.renderRegion(scrollX, scrollY, left, top, right, bottom);

0 commit comments

Comments
 (0)