2017-09-12 23:58:25 +00:00
|
|
|
var GameObject = require('../../GameObject');
|
2018-01-24 22:29:57 +00:00
|
|
|
var Utils = require('../../../renderer/webgl/Utils');
|
2017-09-12 23:58:25 +00:00
|
|
|
|
2018-01-24 22:29:57 +00:00
|
|
|
var DynamicTilemapLayerWebGLRenderer = function (renderer, tilemapLayer, interpolationPercentage, camera)
|
2017-06-09 04:00:12 +00:00
|
|
|
{
|
2018-01-24 22:29:57 +00:00
|
|
|
if (GameObject.RENDER_MASK !== tilemapLayer.renderFlags || (tilemapLayer.cameraFilter > 0 && (tilemapLayer.cameraFilter & camera._id)))
|
2017-06-09 04:00:12 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-01-24 22:29:57 +00:00
|
|
|
tilemapLayer.cull(camera);
|
2017-06-22 02:19:03 +00:00
|
|
|
|
2018-01-24 22:29:57 +00:00
|
|
|
var renderTiles = tilemapLayer.culledTiles;
|
2017-06-09 04:00:12 +00:00
|
|
|
var length = renderTiles.length;
|
2018-01-24 22:29:57 +00:00
|
|
|
var texture = tilemapLayer.tileset.image.get().source.glTexture;
|
|
|
|
var tileset = tilemapLayer.tileset;
|
|
|
|
var scrollFactorX = tilemapLayer.scrollFactorX;
|
|
|
|
var scrollFactorY = tilemapLayer.scrollFactorY;
|
|
|
|
var alpha = tilemapLayer.alpha;
|
|
|
|
var x = tilemapLayer.x;
|
|
|
|
var y = tilemapLayer.y;
|
|
|
|
var sx = tilemapLayer.scaleX;
|
|
|
|
var sy = tilemapLayer.scaleY;
|
|
|
|
var getTint = Utils.getTintAppendFloatAlpha;
|
|
|
|
var pipeline = renderer.pipelines.TextureTintPipeline;
|
2017-06-09 04:00:12 +00:00
|
|
|
|
|
|
|
for (var index = 0; index < length; ++index)
|
|
|
|
{
|
2017-06-22 02:19:03 +00:00
|
|
|
var tile = renderTiles[index];
|
2017-11-03 16:52:57 +00:00
|
|
|
|
2017-11-14 21:35:18 +00:00
|
|
|
var tileTexCoords = tileset.getTileTextureCoordinates(tile.index);
|
|
|
|
if (tileTexCoords === null) { continue; }
|
2017-11-03 16:52:57 +00:00
|
|
|
|
2017-11-15 02:45:05 +00:00
|
|
|
var frameWidth = tile.width * (tile.flipX ? -1 : 1);
|
|
|
|
var frameHeight = tile.height * (tile.flipY ? -1 : 1);
|
|
|
|
var frameX = tileTexCoords.x + (tile.flipX ? tile.width : 0);
|
|
|
|
var frameY = tileTexCoords.y + (tile.flipY ? tile.height : 0);
|
2018-01-24 22:29:57 +00:00
|
|
|
var tint = getTint(tile.tint, alpha * tile.alpha);
|
2017-11-15 02:45:05 +00:00
|
|
|
|
2018-01-24 22:29:57 +00:00
|
|
|
pipeline.batchTexture(
|
2017-06-22 02:19:03 +00:00
|
|
|
texture,
|
2018-01-25 00:15:51 +00:00
|
|
|
texture.width, texture.height,
|
2018-01-25 05:26:14 +00:00
|
|
|
x + tile.pixelX * sx, y + tile.pixelY * sy,
|
|
|
|
tile.width * sx, tile.height * sy,
|
2018-01-24 22:29:57 +00:00
|
|
|
1, 1,
|
|
|
|
0,
|
|
|
|
false, false,
|
2017-06-22 02:19:03 +00:00
|
|
|
scrollFactorX, scrollFactorY,
|
2018-01-24 22:29:57 +00:00
|
|
|
0, 0,
|
2017-11-15 02:45:05 +00:00
|
|
|
frameX, frameY, frameWidth, frameHeight,
|
2018-01-24 22:29:57 +00:00
|
|
|
tint, tint, tint, tint,
|
2018-01-25 00:15:51 +00:00
|
|
|
0, 0,
|
2018-01-24 22:29:57 +00:00
|
|
|
camera
|
2017-06-22 02:19:03 +00:00
|
|
|
);
|
2018-01-24 22:29:57 +00:00
|
|
|
}
|
2017-06-09 04:00:12 +00:00
|
|
|
};
|
|
|
|
|
2017-11-09 18:18:23 +00:00
|
|
|
module.exports = DynamicTilemapLayerWebGLRenderer;
|