phaser/v3/src/gameobjects/tilemap/dynamiclayer/DynamicTilemapLayer.js

177 lines
5.1 KiB
JavaScript
Raw Normal View History

2017-06-09 04:00:12 +00:00
var Class = require('../../../utils/Class');
var GameObject = require('../../GameObject');
var Components = require('../../components');
var DynamicTilemapLayerRender = require('./DynamicTilemapLayerRender');
var TilemapComponents = require('../components');
2017-06-09 04:00:12 +00:00
var DynamicTilemapLayer = new Class({
2017-06-09 04:00:12 +00:00
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,
2017-06-22 02:19:03 +00:00
Components.ScrollFactor,
DynamicTilemapLayerRender
2017-06-09 04:00:12 +00:00
],
initialize:
function DynamicTilemapLayer (scene, tilemap, layerIndex, tileset, x, y)
2017-06-09 04:00:12 +00:00
{
GameObject.call(this, scene, 'DynamicTilemapLayer');
2017-06-09 04:00:12 +00:00
this.map = tilemap;
this.layerIndex = layerIndex;
this.layer = tilemap.layers[layerIndex];
this.tileset = tileset;
// Link the layer data with this dynamic tilemap layer
this.layer.tilemapLayer = this;
2017-06-09 04:00:12 +00:00
this.culledTiles = [];
this.setTexture(tileset.image.key);
2017-06-09 04:00:12 +00:00
this.setPosition(x, y);
this.setSizeToFrame();
this.setOrigin();
this.setSize(this.map.tileWidth * this.layer.width, this.map.tileheight * this.layer.height);
this.skipIndexZero = false;
2017-06-09 04:00:12 +00:00
},
cull: function (camera)
2017-06-09 04:00:12 +00:00
{
TilemapComponents.CullTiles(this.layer, camera, this.culledTiles);
},
copy: function (srcTileX, srcTileY, width, height, destTileX, destTileY)
{
TilemapComponents.Copy(srcTileX, srcTileY, width, height, destTileX, destTileY, this.layer);
return this;
},
destroy: function ()
{
this.layer.tilemapLayer = undefined;
this.map = undefined;
this.layer = undefined;
this.tileset = undefined;
this.culledTiles.length = 0;
GameObject.prototype.destroy.call(this);
},
fill: function (index, tileX, tileY, width, height)
{
TilemapComponents.Fill(index, tileX, tileY, width, height, this.layer);
return this;
},
findByIndex: function (findIndex, skip, reverse)
{
return TilemapComponents.FindByIndex(findIndex, skip, reverse, this.layer);
},
forEachTile: function (callback, context, tileX, tileY, width, height)
{
TilemapComponents.ForEachTile(callback, context, tileX, tileY, width, height, this.layer);
return this;
},
getTileAt: function (tileX, tileY, nonNull)
{
2017-11-16 19:09:07 +00:00
return TilemapComponents.GetTileAt(tileX, tileY, nonNull, this.layer);
},
getTileAtWorldXY: function (worldX, worldY, nonNull, camera)
2017-11-16 19:27:52 +00:00
{
return TilemapComponents.GetTileAtWorldXY(worldX, worldY, nonNull, camera, this.layer);
2017-11-16 19:27:52 +00:00
},
getTilesWithin: function (tileX, tileY, width, height)
{
return TilemapComponents.GetTilesWithin(tileX, tileY, width, height, this.layer);
},
hasTileAt: function (tileX, tileY)
{
return TilemapComponents.HasTileAt(tileX, tileY, this.layer);
},
hasTileAtWorldXY: function (worldX, worldY, camera)
{
return TilemapComponents.HasTileAtWorldXY(worldX, worldY, camera, this.layer);
},
2017-11-16 19:09:07 +00:00
putTile: function (tile, tileX, tileY)
{
return TilemapComponents.PutTile(tile, tileX, tileY, this.layer);
},
putTileWorldXY: function (tile, worldX, worldY, camera)
{
return TilemapComponents.PutTileWorldXY(tile, worldX, worldY, camera, this.layer);
},
randomize: function (tileX, tileY, width, height, indices)
{
TilemapComponents.Randomize(tileX, tileY, width, height, indices, this.layer);
return this;
},
2017-11-16 19:09:07 +00:00
removeTile: function (tileX, tileY, replaceWithNull)
{
return TilemapComponents.RemoveTile(tileX, tileY, replaceWithNull, this.layer);
},
removeTileWorldXY: function (worldX, worldY, replaceWithNull, camera)
{
return TilemapComponents.RemoveTileWorldXY(worldX, worldY, replaceWithNull, camera, this.layer);
},
replaceByIndex: function (findIndex, newIndex, tileX, tileY, width, height)
{
TilemapComponents.ReplaceByIndex(findIndex, newIndex, tileX, tileY, width, height, this.layer);
return this;
},
shuffle: function (tileX, tileY, width, height)
{
TilemapComponents.Shuffle(tileX, tileY, width, height, this.layer);
return this;
},
2017-06-22 02:19:03 +00:00
swapByIndex: function (indexA, indexB, tileX, tileY, width, height)
{
TilemapComponents.SwapByIndex(indexA, indexB, tileX, tileY, width, height, this.layer);
return this;
},
worldToTileX: function (worldX, camera)
{
return TilemapComponents.WorldToTileX(worldX, camera, this.layer);
},
worldToTileY: function (worldY, camera)
{
return TilemapComponents.WorldToTileY(worldY, camera, this.layer);
},
worldToTileXY: function (worldX, worldY, point, camera)
{
return TilemapComponents.WorldToTileXY(worldX, worldY, point, camera, this.layer);
}
2017-06-09 04:00:12 +00:00
});
module.exports = DynamicTilemapLayer;