From fe835266fdee3ad11a0ca7a99cba995a2cd04117 Mon Sep 17 00:00:00 2001 From: Felipe Alfonso Date: Fri, 23 Jun 2017 18:42:08 -0400 Subject: [PATCH] Fixed issue with camera bounds and static tilemap culling --- v3/src/camera/Camera.js | 13 +++++++++---- v3/src/checksum.js | 2 +- .../gameobjects/tilemap/static/StaticTilemap.js | 16 ++++++++-------- .../tilemap/static/StaticTilemapWebGLRenderer.js | 7 +++++++ 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/v3/src/camera/Camera.js b/v3/src/camera/Camera.js index 413368b98..c6a5719d0 100644 --- a/v3/src/camera/Camera.js +++ b/v3/src/camera/Camera.js @@ -230,22 +230,27 @@ Camera.prototype = { if (this.useBounds) { 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) { 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) { this.scrollY = bounds.y; } - else if (this.scrollY > bounds.bottom - height) + if (this.scrollY > boundsB) { - this.scrollY = bounds.bottom - height; + this.scrollY = boundsB; } } diff --git a/v3/src/checksum.js b/v3/src/checksum.js index cb9bb05b3..319cf1c80 100644 --- a/v3/src/checksum.js +++ b/v3/src/checksum.js @@ -1,4 +1,4 @@ var CHECKSUM = { -build: '4b54cc50-5861-11e7-9b35-1d9d7e24430e' +build: '1146c000-5865-11e7-a80a-994e778896fe' }; module.exports = CHECKSUM; \ No newline at end of file diff --git a/v3/src/gameobjects/tilemap/static/StaticTilemap.js b/v3/src/gameobjects/tilemap/static/StaticTilemap.js index d99c31476..55984a950 100644 --- a/v3/src/gameobjects/tilemap/static/StaticTilemap.js +++ b/v3/src/gameobjects/tilemap/static/StaticTilemap.js @@ -177,15 +177,15 @@ var StaticTilemap = new Class({ var pixelWidth = this.mapWidth * tileWidth; var pixelHeight = this.mapHeight * tileHeight; - if (pixelX < camera.width + tileWidth && - pixelX + pixelWidth > -tileWidth && - pixelY < camera.height + tileHeight && - pixelY + pixelHeight > -tileHeight) + if (pixelX < camera.x + camera.width + (tileWidth * 2) && + pixelX + pixelWidth > camera.x + -(tileWidth * 2) && + pixelY < camera.y + camera.height + (tileHeight * 2) && + pixelY + pixelHeight > camera.y + -(tileHeight * 2)) { - var interX = Math.max(pixelX, -tileWidth); - var interY = Math.max(pixelY, -tileHeight); - var interWidth = Math.min(pixelX + pixelWidth, camera.width + tileWidth) - interX; - var interHeight = Math.min(pixelY + pixelHeight, camera.height + tileHeight) - interY; + var interX = Math.max(pixelX, camera.x + -(tileWidth * 2)); + var interY = Math.max(pixelY, camera.y + -(tileHeight * 2)); + var interWidth = Math.min(pixelX + pixelWidth, camera.x + camera.width + (tileWidth * 2)) - interX; + var interHeight = Math.min(pixelY + pixelHeight, camera.y + camera.height + (tileHeight * 2)) - interY; interX = ((interX + (camera.scrollX * this.scrollFactorX)) / tileWidth)|0; interY = ((interY + (camera.scrollY * this.scrollFactorY)) / tileHeight)|0; diff --git a/v3/src/gameobjects/tilemap/static/StaticTilemapWebGLRenderer.js b/v3/src/gameobjects/tilemap/static/StaticTilemapWebGLRenderer.js index 421ad9d6a..108a5a578 100644 --- a/v3/src/gameobjects/tilemap/static/StaticTilemapWebGLRenderer.js +++ b/v3/src/gameobjects/tilemap/static/StaticTilemapWebGLRenderer.js @@ -12,7 +12,14 @@ var StaticTilemapWebGLRenderer = function (renderer, src, interpolationPercentag renderer.setRenderer(gameObject.tilemapRenderer, frame.texture.source[frame.sourceIndex].glTexture, gameObject.renderTarget); gameObject.tilemapRenderer.bind(); gameObject.upload(camera); + //gameObject.cull(camera); 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); };