diff --git a/v3/src/checksum.js b/v3/src/checksum.js index 688f5d498..a910e3ceb 100644 --- a/v3/src/checksum.js +++ b/v3/src/checksum.js @@ -1,4 +1,4 @@ var CHECKSUM = { -build: '6f76aea0-4c90-11e7-93fa-3f889df529a8' +build: '0ead5460-4cc8-11e7-b402-85a6b30f7408' }; module.exports = CHECKSUM; \ No newline at end of file diff --git a/v3/src/gameobjects/index.js b/v3/src/gameobjects/index.js index 424b16b8d..0c6acf115 100644 --- a/v3/src/gameobjects/index.js +++ b/v3/src/gameobjects/index.js @@ -17,6 +17,7 @@ require('./tilesprite/TileSpriteFactory'); require('./mesh/MeshFactory'); require('./quad/QuadFactory'); require('./tilemap/static/StaticTilemapFactory'); +require('./tilemap/dynamic/TilemapFactory'); // Phaser.GameObjects @@ -39,5 +40,6 @@ module.exports = { EffectLayer: require('./effectlayer/EffectLayer'), Mesh: require('./mesh/Mesh'), Quad: require('./quad/Quad'), - StaticTilemap: require('./tilemap/static/StaticTilemap') + StaticTilemap: require('./tilemap/static/StaticTilemap'), + Tilemap: require('./tilemap/dynamic/Tilemap'), }; diff --git a/v3/src/gameobjects/tilemap/dynamic/Tile.js b/v3/src/gameobjects/tilemap/dynamic/Tile.js new file mode 100644 index 000000000..823538b5a --- /dev/null +++ b/v3/src/gameobjects/tilemap/dynamic/Tile.js @@ -0,0 +1,14 @@ +function Tile(properties) +{ + this.id = properties.id; + this.x = properties.x; + this.y = properties.y; + this.width = properties.width; + this.height = properties.height; + this.frame = properties.frame; + this.alpha = 1.0; + this.tint = 0xFFFFFF; + this.visible = false; +} + +module.exports = Tile; diff --git a/v3/src/gameobjects/tilemap/dynamic/Tilemap.js b/v3/src/gameobjects/tilemap/dynamic/Tilemap.js new file mode 100644 index 000000000..fa2ed71b2 --- /dev/null +++ b/v3/src/gameobjects/tilemap/dynamic/Tilemap.js @@ -0,0 +1,92 @@ + +var Class = require('../../../utils/Class'); +var GameObject = require('../../GameObject'); +var Components = require('../../../components'); +var TilemapRender = require('./TilemapRender'); +var Tile = require('./Tile'); + +var Tilemap = new Class({ + + Extends: GameObject, + + Mixins: [ + Components.Alpha, + Components.BlendMode, + Components.Flip, + Components.GetBounds, + Components.Origin, + Components.RenderTarget, + Components.ScaleMode, + Components.Size, + Components.Texture, + Components.Transform, + Components.Visible, + TilemapRender + ], + + initialize: + + function Tilemap (state, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, texture, frame) + { + GameObject.call(this, state, 'Tilemap'); + + this.mapData = mapData; + this.tileWidth = tileWidth; + this.tileHeight = tileHeight; + this.mapWidth = mapWidth; + this.mapHeight = mapHeight; + this.tileArray = []; + this.culledTiles = []; + this.setTexture(texture, frame); + this.setPosition(x, y); + this.setSizeToFrame(); + this.setOrigin(); + this.setSize(tileWidth * mapWidth, tileHeight * mapHeight); + this.buildTilemap(); + }, + + buildTilemap: function () + { + var tileArray = this.tileArray; + var mapData = this.mapData; + var frame = this.frame; + var tileWidth = this.tileWidth; + var tileHeight = this.tileHeight; + var width = this.texture.source[0].width; + var height = this.texture.source[0].height; + var mapWidth = this.mapWidth; + var mapHeight = this.mapHeight; + var setWidth = width / tileWidth; + + tileArray.length = 0; + + for (var y = 0; y < mapHeight; ++y) + { + for (var x = 0; x < mapWidth; ++x) + { + var tileId = mapData[y * mapWidth + x]; + var rectx = ((tileId % setWidth)|0) * tileWidth; + var recty = ((tileId / setWidth)|0) * tileHeight; + var tx = x * tileWidth; + var ty = y * tileHeight; + + tileArray.push(new Tile({ + id: tileId, + x: tx, + y: ty, + width: tileWidth, + height: tileHeight, + frame: frame + })); + } + } + }, + + cull: function (rect) + { + /* implement tilemap culling */ + } + +}); + +module.exports = Tilemap; diff --git a/v3/src/gameobjects/tilemap/dynamic/TilemapCanvasRenderer.js b/v3/src/gameobjects/tilemap/dynamic/TilemapCanvasRenderer.js new file mode 100644 index 000000000..e1b08e8c1 --- /dev/null +++ b/v3/src/gameobjects/tilemap/dynamic/TilemapCanvasRenderer.js @@ -0,0 +1,9 @@ +var TilemapCanvasRenderer = function (renderer, src, interpolationPercentage, camera) +{ + if (this.renderMask !== this.renderFlags) + { + return; + } +}; + +module.exports = TilemapCanvasRenderer; diff --git a/v3/src/gameobjects/tilemap/dynamic/TilemapFactory.js b/v3/src/gameobjects/tilemap/dynamic/TilemapFactory.js new file mode 100644 index 000000000..abd19f7cc --- /dev/null +++ b/v3/src/gameobjects/tilemap/dynamic/TilemapFactory.js @@ -0,0 +1,21 @@ + +var Tilemap = require('./Tilemap'); +var FactoryContainer = require('../../../gameobjects/FactoryContainer'); + +var TilemapFactory = { + + KEY: 'tilemap', + + add: function (mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, texture, frame) + { + 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) + { + return new Tilemap(this.state, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, texture, frame); + } + +}; + +module.exports = FactoryContainer.register(TilemapFactory); diff --git a/v3/src/gameobjects/tilemap/dynamic/TilemapRender.js b/v3/src/gameobjects/tilemap/dynamic/TilemapRender.js new file mode 100644 index 000000000..196b07f92 --- /dev/null +++ b/v3/src/gameobjects/tilemap/dynamic/TilemapRender.js @@ -0,0 +1,6 @@ +module.exports = { + + renderCanvas: require('./TilemapCanvasRenderer'), + renderWebGL: require('./TilemapWebGLRenderer') + +}; diff --git a/v3/src/gameobjects/tilemap/dynamic/TilemapWebGLRenderer.js b/v3/src/gameobjects/tilemap/dynamic/TilemapWebGLRenderer.js new file mode 100644 index 000000000..c6849c758 --- /dev/null +++ b/v3/src/gameobjects/tilemap/dynamic/TilemapWebGLRenderer.js @@ -0,0 +1,18 @@ +var TilemapWebGLRenderer = function (renderer, gameObject, interpolationPercentage, camera) +{ + if (this.renderMask !== this.renderFlags) + { + return; + } + + var renderTiles = gameObject.tileArray; + var length = renderTiles.length; + + for (var index = 0; index < length; ++index) + { + + } + +}; + +module.exports = TilemapWebGLRenderer;