Fixed issue with camera bounds and static tilemap culling

This commit is contained in:
Felipe Alfonso 2017-06-23 18:42:08 -04:00
parent 441becd618
commit fe835266fd
4 changed files with 25 additions and 13 deletions

View file

@ -230,22 +230,27 @@ Camera.prototype = {
if (this.useBounds) if (this.useBounds)
{ {
var bounds = this._bounds; var bounds = this._bounds;
var boundsX = bounds.x;
var boundsY = bounds.y;
var boundsR = Math.max(bounds.right - width, width);
var boundsB = Math.max(bounds.bottom - height, height);
if (this.scrollX < bounds.x) if (this.scrollX < bounds.x)
{ {
this.scrollX = bounds.x; this.scrollX = bounds.x;
} }
else if (this.scrollX > bounds.right - width) if (this.scrollX > boundsR)
{ {
this.scrollX = bounds.right - width; this.scrollX = boundsR;
} }
if (this.scrollY < bounds.y) if (this.scrollY < bounds.y)
{ {
this.scrollY = bounds.y; this.scrollY = bounds.y;
} }
else if (this.scrollY > bounds.bottom - height) if (this.scrollY > boundsB)
{ {
this.scrollY = bounds.bottom - height; this.scrollY = boundsB;
} }
} }

View file

@ -1,4 +1,4 @@
var CHECKSUM = { var CHECKSUM = {
build: '4b54cc50-5861-11e7-9b35-1d9d7e24430e' build: '1146c000-5865-11e7-a80a-994e778896fe'
}; };
module.exports = CHECKSUM; module.exports = CHECKSUM;

View file

@ -177,15 +177,15 @@ var StaticTilemap = new Class({
var pixelWidth = this.mapWidth * tileWidth; var pixelWidth = this.mapWidth * tileWidth;
var pixelHeight = this.mapHeight * tileHeight; var pixelHeight = this.mapHeight * tileHeight;
if (pixelX < camera.width + tileWidth && if (pixelX < camera.x + camera.width + (tileWidth * 2) &&
pixelX + pixelWidth > -tileWidth && pixelX + pixelWidth > camera.x + -(tileWidth * 2) &&
pixelY < camera.height + tileHeight && pixelY < camera.y + camera.height + (tileHeight * 2) &&
pixelY + pixelHeight > -tileHeight) pixelY + pixelHeight > camera.y + -(tileHeight * 2))
{ {
var interX = Math.max(pixelX, -tileWidth); var interX = Math.max(pixelX, camera.x + -(tileWidth * 2));
var interY = Math.max(pixelY, -tileHeight); var interY = Math.max(pixelY, camera.y + -(tileHeight * 2));
var interWidth = Math.min(pixelX + pixelWidth, camera.width + tileWidth) - interX; var interWidth = Math.min(pixelX + pixelWidth, camera.x + camera.width + (tileWidth * 2)) - interX;
var interHeight = Math.min(pixelY + pixelHeight, camera.height + tileHeight) - interY; var interHeight = Math.min(pixelY + pixelHeight, camera.y + camera.height + (tileHeight * 2)) - interY;
interX = ((interX + (camera.scrollX * this.scrollFactorX)) / tileWidth)|0; interX = ((interX + (camera.scrollX * this.scrollFactorX)) / tileWidth)|0;
interY = ((interY + (camera.scrollY * this.scrollFactorY)) / tileHeight)|0; interY = ((interY + (camera.scrollY * this.scrollFactorY)) / tileHeight)|0;

View file

@ -12,7 +12,14 @@ var StaticTilemapWebGLRenderer = function (renderer, src, interpolationPercentag
renderer.setRenderer(gameObject.tilemapRenderer, frame.texture.source[frame.sourceIndex].glTexture, gameObject.renderTarget); renderer.setRenderer(gameObject.tilemapRenderer, frame.texture.source[frame.sourceIndex].glTexture, gameObject.renderTarget);
gameObject.tilemapRenderer.bind(); gameObject.tilemapRenderer.bind();
gameObject.upload(camera); gameObject.upload(camera);
//gameObject.cull(camera);
gameObject.vbo.bind(); gameObject.vbo.bind();
//var vertexCount = gameObject.cullEnd - gameObject.cullStart;
//if (vertexCount > 0)
//{
// gl.drawArrays(gl.TRIANGLES, gameObject.cullStart, vertexCount);
//}
gl.drawArrays(gl.TRIANGLES, 0, gameObject.vertexCount); gl.drawArrays(gl.TRIANGLES, 0, gameObject.vertexCount);
}; };