2017-09-12 23:58:25 +00:00
|
|
|
var GameObject = require('../../GameObject');
|
|
|
|
|
2017-11-09 18:18:23 +00:00
|
|
|
var DynamicTilemapLayerWebGLRenderer = function (renderer, gameObject, interpolationPercentage, camera)
|
2017-06-09 04:00:12 +00:00
|
|
|
{
|
2017-09-12 23:58:25 +00:00
|
|
|
if (GameObject.RENDER_MASK !== gameObject.renderFlags || (gameObject.cameraFilter > 0 && (gameObject.cameraFilter & camera._id)))
|
2017-06-09 04:00:12 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-09-12 23:58:25 +00:00
|
|
|
gameObject.cull(camera);
|
2017-06-22 02:19:03 +00:00
|
|
|
|
|
|
|
var renderTiles = gameObject.culledTiles;
|
2017-06-09 04:00:12 +00:00
|
|
|
var length = renderTiles.length;
|
2017-06-22 02:19:03 +00:00
|
|
|
var batch = renderer.spriteBatch;
|
|
|
|
var texture = gameObject.texture.source[0].glTexture;
|
|
|
|
var textureWidth = texture.width;
|
|
|
|
var textureHeight = texture.height;
|
2017-11-14 21:35:18 +00:00
|
|
|
var tileset = this.tileset;
|
2017-06-22 02:19:03 +00:00
|
|
|
var renderTarget = gameObject.renderTarget;
|
|
|
|
var scrollFactorX = gameObject.scrollFactorX;
|
|
|
|
var scrollFactorY = gameObject.scrollFactorY;
|
|
|
|
var alpha = gameObject.alpha;
|
|
|
|
var x = gameObject.x;
|
|
|
|
var y = gameObject.y;
|
2017-11-25 23:09:56 +00:00
|
|
|
var sx = gameObject.scaleX;
|
|
|
|
var sy = gameObject.scaleY;
|
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);
|
|
|
|
|
2017-06-22 02:19:03 +00:00
|
|
|
batch.addTileTextureRect(
|
|
|
|
texture,
|
2017-11-25 23:09:56 +00:00
|
|
|
(x + tile.worldX) * sx, (y + tile.worldY) * sy,
|
|
|
|
tile.width * sx, tile.height * sy,
|
|
|
|
alpha * tile.alpha, tile.tint,
|
2017-06-22 02:19:03 +00:00
|
|
|
scrollFactorX, scrollFactorY,
|
2017-06-26 12:16:27 +00:00
|
|
|
textureWidth, textureHeight,
|
2017-11-15 02:45:05 +00:00
|
|
|
frameX, frameY, frameWidth, frameHeight,
|
2017-06-22 02:19:03 +00:00
|
|
|
camera,
|
|
|
|
renderTarget
|
|
|
|
);
|
2017-06-09 04:00:12 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-11-09 18:18:23 +00:00
|
|
|
module.exports = DynamicTilemapLayerWebGLRenderer;
|