mirror of
https://github.com/photonstorm/phaser
synced 2024-11-23 13:13:43 +00:00
Tilemap Progress
This commit is contained in:
parent
c0b532da1a
commit
b7fd964df1
8 changed files with 164 additions and 2 deletions
|
@ -1,4 +1,4 @@
|
|||
var CHECKSUM = {
|
||||
build: '6f76aea0-4c90-11e7-93fa-3f889df529a8'
|
||||
build: '0ead5460-4cc8-11e7-b402-85a6b30f7408'
|
||||
};
|
||||
module.exports = CHECKSUM;
|
|
@ -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'),
|
||||
};
|
||||
|
|
14
v3/src/gameobjects/tilemap/dynamic/Tile.js
Normal file
14
v3/src/gameobjects/tilemap/dynamic/Tile.js
Normal file
|
@ -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;
|
92
v3/src/gameobjects/tilemap/dynamic/Tilemap.js
Normal file
92
v3/src/gameobjects/tilemap/dynamic/Tilemap.js
Normal file
|
@ -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;
|
|
@ -0,0 +1,9 @@
|
|||
var TilemapCanvasRenderer = function (renderer, src, interpolationPercentage, camera)
|
||||
{
|
||||
if (this.renderMask !== this.renderFlags)
|
||||
{
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = TilemapCanvasRenderer;
|
21
v3/src/gameobjects/tilemap/dynamic/TilemapFactory.js
Normal file
21
v3/src/gameobjects/tilemap/dynamic/TilemapFactory.js
Normal file
|
@ -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);
|
6
v3/src/gameobjects/tilemap/dynamic/TilemapRender.js
Normal file
6
v3/src/gameobjects/tilemap/dynamic/TilemapRender.js
Normal file
|
@ -0,0 +1,6 @@
|
|||
module.exports = {
|
||||
|
||||
renderCanvas: require('./TilemapCanvasRenderer'),
|
||||
renderWebGL: require('./TilemapWebGLRenderer')
|
||||
|
||||
};
|
18
v3/src/gameobjects/tilemap/dynamic/TilemapWebGLRenderer.js
Normal file
18
v3/src/gameobjects/tilemap/dynamic/TilemapWebGLRenderer.js
Normal file
|
@ -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;
|
Loading…
Reference in a new issue