diff --git a/v3/src/checksum.js b/v3/src/checksum.js index 319cf1c80..09c98b059 100644 --- a/v3/src/checksum.js +++ b/v3/src/checksum.js @@ -1,4 +1,4 @@ var CHECKSUM = { -build: '1146c000-5865-11e7-a80a-994e778896fe' +build: '2e773640-5a69-11e7-ad23-414a67d4aeba' }; module.exports = CHECKSUM; \ No newline at end of file diff --git a/v3/src/gameobjects/tilemap/dynamic/BuildFromConfig.js b/v3/src/gameobjects/tilemap/dynamic/BuildFromConfig.js new file mode 100644 index 000000000..54fbc42a0 --- /dev/null +++ b/v3/src/gameobjects/tilemap/dynamic/BuildFromConfig.js @@ -0,0 +1,26 @@ +var Tilemap = require('./Tilemap'); +var GetValue = require('../../../utils/object/GetValue'); +var BuildGameObject = require('../../BuildGameObject'); + +var BuildFromConfig = function (state, config) +{ + var mapData = GetValue(config, 'map.data', null); + var mapWidth = GetValue(config, 'map.width', 1); + var mapHeight = GetValue(config, 'map.height', 1); + + var x = GetValue(config, 'x', 0); + var y = GetValue(config, 'y', 0); + + var tileWidth = GetValue(config, 'tile.width', 16); + var tileHeight = GetValue(config, 'tile.height', 16); + var tileTexture = GetValue(config, 'tile.texture', null); + var tileFrame = GetValue(config, 'tile.frame', null); + + var map = new Tilemap(state, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileTexture, tileFrame); + + BuildGameObject(state, map, config); + + return map; +}; + +module.exports = BuildFromConfig; diff --git a/v3/src/gameobjects/tilemap/dynamic/Tilemap.js b/v3/src/gameobjects/tilemap/dynamic/Tilemap.js index e464d4984..685ddeee9 100644 --- a/v3/src/gameobjects/tilemap/dynamic/Tilemap.js +++ b/v3/src/gameobjects/tilemap/dynamic/Tilemap.js @@ -46,7 +46,7 @@ var Tilemap = new Class({ this.buildTilemap(); }, - getTotalTileCount: function () + getTotalTileCount: function () { return this.tileArray.length; }, @@ -56,11 +56,11 @@ var Tilemap = new Class({ return this.cull(camera).length; }, - buildTilemap: function () + buildTilemap: function () { var tileArray = this.tileArray; var mapData = this.mapData; - var frame = this.frame; + // var frame = this.frame; var tileWidth = this.tileWidth; var tileHeight = this.tileHeight; var width = this.texture.source[0].width; @@ -76,8 +76,8 @@ var Tilemap = new Class({ for (var x = 0; x < mapWidth; ++x) { var tileId = mapData[y * mapWidth + x]; - var halfTileWidth = (tileWidth) * 0.5; - var halfTileHeight = (tileHeight) * 0.5; + var halfTileWidth = (tileWidth) * 0.5; + var halfTileHeight = (tileHeight) * 0.5; var rectx = (((tileId % setWidth)|0) * tileWidth) + halfTileWidth; var recty = (((tileId / setWidth)|0) * tileHeight) + halfTileHeight; var tx = x * tileWidth; @@ -112,6 +112,7 @@ var Tilemap = new Class({ var cameraH = camera.height; culledTiles.length = 0; + for (var index = 0; index < length; ++index) { var tile = tiles[index]; @@ -144,21 +145,25 @@ var Tilemap = new Class({ var iy = (y|0); var tiles = this.tileArray; var index = iy * this.mapWidth + ix; + if (index < tiles.length) { return tiles[index]; } + return null; }, getTileAtIndex: function (index) { var tiles = this.tileArray; + if (index < tiles.length) { return tiles[index]; } - return null; + + return null; } }); diff --git a/v3/src/gameobjects/tilemap/dynamic/TilemapFactory.js b/v3/src/gameobjects/tilemap/dynamic/TilemapFactory.js index abd19f7cc..a8c9dc3e3 100644 --- a/v3/src/gameobjects/tilemap/dynamic/TilemapFactory.js +++ b/v3/src/gameobjects/tilemap/dynamic/TilemapFactory.js @@ -1,5 +1,6 @@ var Tilemap = require('./Tilemap'); +var BuildFromConfig = require('./BuildFromConfig'); var FactoryContainer = require('../../../gameobjects/FactoryContainer'); var TilemapFactory = { @@ -11,9 +12,9 @@ var TilemapFactory = { return this.children.add(new Tilemap(this.state, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, texture, frame)); }, - make: function (mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, texture, frame) + make: function (config) { - return new Tilemap(this.state, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, texture, frame); + return BuildFromConfig(this.state, config); } }; diff --git a/v3/src/gameobjects/tilemap/dynamic/TilemapWebGLRenderer.js b/v3/src/gameobjects/tilemap/dynamic/TilemapWebGLRenderer.js index e33212729..9d73a9cab 100644 --- a/v3/src/gameobjects/tilemap/dynamic/TilemapWebGLRenderer.js +++ b/v3/src/gameobjects/tilemap/dynamic/TilemapWebGLRenderer.js @@ -27,7 +27,7 @@ var TilemapWebGLRenderer = function (renderer, gameObject, interpolationPercenta texture, x + tile.x, y + tile.y, tile.width, tile.height, alpha * tile.alpha, tile.tint, scrollFactorX, scrollFactorY, - textureWidth, textureHeight, + textureWidth, textureHeight, tile.frameX, tile.frameY, tile.frameWidth, tile.frameHeight, camera, renderTarget diff --git a/v3/src/gameobjects/tilemap/static/BuildFromConfig.js b/v3/src/gameobjects/tilemap/static/BuildFromConfig.js new file mode 100644 index 000000000..91d7e314a --- /dev/null +++ b/v3/src/gameobjects/tilemap/static/BuildFromConfig.js @@ -0,0 +1,26 @@ +var StaticTilemap = require('./StaticTilemap'); +var GetValue = require('../../../utils/object/GetValue'); +var BuildGameObject = require('../../BuildGameObject'); + +var BuildFromConfig = function (state, config) +{ + var mapData = GetValue(config, 'map.data', null); + var mapWidth = GetValue(config, 'map.width', 1); + var mapHeight = GetValue(config, 'map.height', 1); + + var x = GetValue(config, 'x', 0); + var y = GetValue(config, 'y', 0); + + var tileWidth = GetValue(config, 'tile.width', 16); + var tileHeight = GetValue(config, 'tile.height', 16); + var tileTexture = GetValue(config, 'tile.texture', null); + var tileFrame = GetValue(config, 'tile.frame', null); + + var map = new StaticTilemap(state, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileTexture, tileFrame); + + BuildGameObject(state, map, config); + + return map; +}; + +module.exports = BuildFromConfig; diff --git a/v3/src/gameobjects/tilemap/static/StaticTilemapFactory.js b/v3/src/gameobjects/tilemap/static/StaticTilemapFactory.js index 65ed60f02..fd8664357 100644 --- a/v3/src/gameobjects/tilemap/static/StaticTilemapFactory.js +++ b/v3/src/gameobjects/tilemap/static/StaticTilemapFactory.js @@ -1,5 +1,6 @@ var StaticTilemap = require('./StaticTilemap'); +var BuildFromConfig = require('./BuildFromConfig'); var FactoryContainer = require('../../../gameobjects/FactoryContainer'); var StaticTilemapFactory = { @@ -11,9 +12,9 @@ var StaticTilemapFactory = { return this.children.add(new StaticTilemap(this.state, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, texture, frame)); }, - make: function (mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, texture, frame) + make: function (config) { - return new StaticTilemap(this.state, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, texture, frame); + return BuildFromConfig(this.state, config); } };