Skip to content

Commit 0904e38

Browse files
committed
Use firstgid (TODO: assumes tileset 0 currently, needs to calculate the correct tileset) to fix the 'out by one' tilemap example errors.
Handle empty VBO case, and make sure we only drawArrays the correct number of vertices (to fix the large corrupt block in the top-right corner of many example demos).
1 parent 0dd3610 commit 0904e38

1 file changed

Lines changed: 13 additions & 9 deletions

File tree

src/pixi/extras/Tilemap.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,8 @@ PIXI.Tilemap.prototype._renderVisibleLayer = function( _layer, renderSession )
270270
for(var tx = firstX; tx < lastX; tx++)
271271
{
272272
// get the tile index from the map
273-
var tile = layerRow[tx].index - 1;
273+
// TODO: hardwired to the first tileset, should use TilemapLayerGL.resolveTileset to work out the correct one(?)
274+
var tile = layerRow[tx].index - this.map.tilesets[0].firstgid;
274275

275276
// if it's not an empty tile...
276277
if ( tile >= 0 )
@@ -339,17 +340,20 @@ PIXI.Tilemap.prototype._renderVisibleLayer = function( _layer, renderSession )
339340
}
340341
}
341342

342-
// set the scroll offset (in screen units)
343-
gl.uniform2f( shader.uScrollOffset, this.scrollX * iWide, -this.scrollY * iHigh );
343+
if ( c > 0 )
344+
{
345+
// set the scroll offset (in screen units)
346+
gl.uniform2f( shader.uScrollOffset, this.scrollX * iWide, -this.scrollY * iHigh );
344347

345-
// upload the VBO
346-
gl.bufferData( gl.ARRAY_BUFFER, buffer, gl.STATIC_DRAW );
348+
// upload the VBO
349+
gl.bufferData( gl.ARRAY_BUFFER, buffer, gl.STATIC_DRAW );
347350

348-
// prepare the shader attributes
349-
gl.vertexAttribPointer( shader.aPosition, 4, gl.FLOAT, false, 0, 0 );
351+
// prepare the shader attributes
352+
gl.vertexAttribPointer( shader.aPosition, 4, gl.FLOAT, false, 0, 0 );
350353

351-
// draw the entire VBO in one call
352-
gl.drawArrays(gl.TRIANGLE_STRIP, 0, (lastX - firstX) * (lastY - firstY) * 6 - 2); // 4 + 2 (vertices + degenerates)
354+
// draw the entire VBO in one call
355+
gl.drawArrays(gl.TRIANGLE_STRIP, 0, Math.floor(c / 4));
356+
}
353357
};
354358

355359

0 commit comments

Comments
 (0)