Skip to content

Commit fe83526

Browse files
committed
Fixed issue with camera bounds and static tilemap culling
1 parent 441becd commit fe83526

4 files changed

Lines changed: 25 additions & 13 deletions

File tree

v3/src/camera/Camera.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,22 +230,27 @@ Camera.prototype = {
230230
if (this.useBounds)
231231
{
232232
var bounds = this._bounds;
233+
var boundsX = bounds.x;
234+
var boundsY = bounds.y;
235+
var boundsR = Math.max(bounds.right - width, width);
236+
var boundsB = Math.max(bounds.bottom - height, height);
233237

234238
if (this.scrollX < bounds.x)
235239
{
236240
this.scrollX = bounds.x;
237241
}
238-
else if (this.scrollX > bounds.right - width)
242+
if (this.scrollX > boundsR)
239243
{
240-
this.scrollX = bounds.right - width;
244+
this.scrollX = boundsR;
241245
}
246+
242247
if (this.scrollY < bounds.y)
243248
{
244249
this.scrollY = bounds.y;
245250
}
246-
else if (this.scrollY > bounds.bottom - height)
251+
if (this.scrollY > boundsB)
247252
{
248-
this.scrollY = bounds.bottom - height;
253+
this.scrollY = boundsB;
249254
}
250255
}
251256

v3/src/checksum.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
var CHECKSUM = {
2-
build: '4b54cc50-5861-11e7-9b35-1d9d7e24430e'
2+
build: '1146c000-5865-11e7-a80a-994e778896fe'
33
};
44
module.exports = CHECKSUM;

v3/src/gameobjects/tilemap/static/StaticTilemap.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,15 @@ var StaticTilemap = new Class({
177177
var pixelWidth = this.mapWidth * tileWidth;
178178
var pixelHeight = this.mapHeight * tileHeight;
179179

180-
if (pixelX < camera.width + tileWidth &&
181-
pixelX + pixelWidth > -tileWidth &&
182-
pixelY < camera.height + tileHeight &&
183-
pixelY + pixelHeight > -tileHeight)
180+
if (pixelX < camera.x + camera.width + (tileWidth * 2) &&
181+
pixelX + pixelWidth > camera.x + -(tileWidth * 2) &&
182+
pixelY < camera.y + camera.height + (tileHeight * 2) &&
183+
pixelY + pixelHeight > camera.y + -(tileHeight * 2))
184184
{
185-
var interX = Math.max(pixelX, -tileWidth);
186-
var interY = Math.max(pixelY, -tileHeight);
187-
var interWidth = Math.min(pixelX + pixelWidth, camera.width + tileWidth) - interX;
188-
var interHeight = Math.min(pixelY + pixelHeight, camera.height + tileHeight) - interY;
185+
var interX = Math.max(pixelX, camera.x + -(tileWidth * 2));
186+
var interY = Math.max(pixelY, camera.y + -(tileHeight * 2));
187+
var interWidth = Math.min(pixelX + pixelWidth, camera.x + camera.width + (tileWidth * 2)) - interX;
188+
var interHeight = Math.min(pixelY + pixelHeight, camera.y + camera.height + (tileHeight * 2)) - interY;
189189

190190
interX = ((interX + (camera.scrollX * this.scrollFactorX)) / tileWidth)|0;
191191
interY = ((interY + (camera.scrollY * this.scrollFactorY)) / tileHeight)|0;

v3/src/gameobjects/tilemap/static/StaticTilemapWebGLRenderer.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,14 @@ var StaticTilemapWebGLRenderer = function (renderer, src, interpolationPercentag
1212
renderer.setRenderer(gameObject.tilemapRenderer, frame.texture.source[frame.sourceIndex].glTexture, gameObject.renderTarget);
1313
gameObject.tilemapRenderer.bind();
1414
gameObject.upload(camera);
15+
//gameObject.cull(camera);
1516
gameObject.vbo.bind();
17+
18+
//var vertexCount = gameObject.cullEnd - gameObject.cullStart;
19+
//if (vertexCount > 0)
20+
//{
21+
// gl.drawArrays(gl.TRIANGLES, gameObject.cullStart, vertexCount);
22+
//}
1623
gl.drawArrays(gl.TRIANGLES, 0, gameObject.vertexCount);
1724
};
1825

0 commit comments

Comments
 (0)