Skip to content

Commit 1594036

Browse files
committed
Tile border added to static tilemap
1 parent eddb17f commit 1594036

4 files changed

Lines changed: 17 additions & 12 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ var BuildFromConfig = function (state, config)
1515
var tileHeight = GetValue(config, 'tile.height', 16);
1616
var tileTexture = GetValue(config, 'tile.texture', null);
1717
var tileFrame = GetValue(config, 'tile.frame', null);
18+
var tileBorder = GetValue(config, 'tile.border', 0);
1819

19-
var map = new StaticTilemap(state, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileTexture, tileFrame);
20+
var map = new StaticTilemap(state, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileBorder, tileTexture, tileFrame);
2021

2122
BuildGameObject(state, map, config);
2223

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ var StaticTilemap = new Class({
2727

2828
initialize:
2929

30-
function StaticTilemap (state, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, texture, frame)
30+
function StaticTilemap (state, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileBorder, texture, frame)
3131
{
3232
GameObject.call(this, state, 'StaticTilemap');
3333

@@ -45,6 +45,7 @@ var StaticTilemap = new Class({
4545
this.vertexCount = 0;
4646
this.cullStart = 0;
4747
this.cullEnd = 0;
48+
this.tileBorder = tileBorder;
4849
this.setTexture(texture, frame);
4950
this.setPosition(x, y);
5051
this.setSizeToFrame();
@@ -62,8 +63,11 @@ var StaticTilemap = new Class({
6263
var vbo = this.vbo;
6364
var mapWidth = this.mapWidth;
6465
var mapHeight = this.mapHeight;
66+
var border = this.tileBorder;
6567
var tileWidth = this.tileWidth;
6668
var tileHeight = this.tileHeight;
69+
var tileWidthBorder = tileWidth + border * 2;
70+
var tileHeightBorder = tileHeight + border * 2;
6771
var bufferData = this.bufferData;
6872
var bufferF32, bufferU32;
6973
var voffset = 0;
@@ -89,10 +93,10 @@ var StaticTilemap = new Class({
8993
for (var x = 0; x < mapWidth; ++x)
9094
{
9195
var tileId = mapData[y * mapWidth + x];
92-
var halfTileWidth = (tileWidth) * 0.5;
93-
var halfTileHeight = (tileHeight) * 0.5;
94-
var rectx = (((tileId % setWidth)|0) * tileWidth) + halfTileWidth;
95-
var recty = (((tileId / setWidth)|0) * tileHeight) + halfTileHeight;
96+
var halfTileWidth = (tileWidthBorder) * 0.5;
97+
var halfTileHeight = (tileHeightBorder) * 0.5;
98+
var rectx = (((tileId % setWidth)|0) * tileWidthBorder) + halfTileWidth;
99+
var recty = (((tileId / setWidth)|0) * tileHeightBorder) + halfTileHeight;
96100
var tx = x * tileWidth;
97101
var ty = y * tileHeight;
98102
var txw = tx + tileWidth;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ var StaticTilemapFactory = {
77

88
KEY: 'staticTilemap',
99

10-
add: function (mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, texture, frame)
10+
add: function (mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileBorder, texture, frame)
1111
{
12-
return this.children.add(new StaticTilemap(this.state, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, texture, frame));
12+
return this.children.add(new StaticTilemap(this.state, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileBorder, texture, frame));
1313
},
1414

1515
make: function (config)

v3/src/renderer/webgl/renderers/spritebatch/SpriteBatch.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -374,10 +374,10 @@ SpriteBatch.prototype = {
374374
var sra, srb, src, srd, sre, srf, cma, cmb, cmc, cmd, cme, cmf;
375375
var halfTileWidth = (width) * 0.5;
376376
var halfTileHeight = (height) * 0.5;
377-
var u0 = (rectX - halfTileWidth) / textureWidth;
378-
var v0 = (rectY - halfTileHeight) / textureHeight;
379-
var u1 = (rectX + halfTileWidth) / textureWidth;
380-
var v1 = (rectY + halfTileHeight) / textureHeight;
377+
var u0 = (rectX - (halfTileWidth - 0.5)) / textureWidth;
378+
var v0 = (rectY - (halfTileHeight - 0.5)) / textureHeight;
379+
var u1 = (rectX + (halfTileWidth - 0.5)) / textureWidth;
380+
var v1 = (rectY + (halfTileHeight - 0.5)) / textureHeight;
381381
var scrollX = camera.scrollX * scrollFactorX;
382382
var scrollY = camera.scrollY * scrollFactorY;
383383

0 commit comments

Comments
 (0)