var Class = require('../../utils/Class'); var Components = require('../components'); var Const = require('./Const'); var GameObject = require('../GameObject'); var Light = require('./Light'); var Render = require('./LightLayerRender'); var SpriteNormalPair = require('./SpriteNormalPair'); var LightLayer = new Class({ Extends: GameObject, Mixins: [Components.Alpha, Components.BlendMode, Components.Origin, Components.ScrollFactor, Components.Visible, Render] , initialize: function LightLayer(scene){ var _this = this; GameObject.call(this, scene, 'LightLayer'); this.renderer = scene.sys.game.renderer; this.passShader = null ; this.gl = null ; this.ambientLightColorR = 0; this.ambientLightColorG = 0; this.ambientLightColorB = 0; this.lightPool = [] ; this.spritePool = [] ; this.lights = [] ; this.sprites = [] ; this._z = 0; this.setOrigin(0, 0); this.renderer.onContextRestored(function (renderer){ this.onContextRestored(renderer); } , this); _AN_Call_init('init', this, scene.sys.game.renderer, this.renderer.hasExtension('WEBGL_draw_buffers')); } , onContextRestored: function (renderer){ _AN_Call_init('init', this, renderer, false ); this.lights.length = Math.min(_AN_Read_length('length', this.lights), Const.MAX_LIGHTS); } , init: function (renderer, deferred){ } , forEachLight: function (callback){ if (!callback) { return ; } var lights = this.lights; var length = _AN_Read_length('length', lights); for (var index = 0; index < length; ++index){ callback(lights[index]); } } , z: function (){ return this._z; } , z: function (newZ){ this._z = newZ; } , setAmbientLightColor: function (r, g, b){ this.ambientLightColorR = r; this.ambientLightColorG = g; this.ambientLightColorB = b; } , getMaxLights: function (){ return (this._isDeferred)? Const.DEFERRED_MAX_LIGHTS: Const.MAX_LIGHTS; } , getLightCount: function (){ return (_AN_Read_length('length', this.lights)); } , isDeferred: function (){ return this._isDeferred; } , addSprite: function (sprite, normalTexture){ var spriteNormalPair; if ((_AN_Read_length('length', this.spritePool)) > 0) { spriteNormalPair = this.spritePool.pop(); spriteNormalPair.set(sprite, normalTexture); } else { spriteNormalPair = new SpriteNormalPair(sprite, normalTexture); } this.scene.sys.displayList.remove(sprite); this.sprites.push(spriteNormalPair); } , removeSprite: function (sprite){ var length = _AN_Read_length('length', this.sprites); for (var index = 0; index < length; ++index){ if (this.sprites[index].spriteRef === sprite) { this.spritePool.push(this.sprites[index]); this.sprites.splice(index, 1); break ; } } return sprite; } , addLight: function (x, y, z, radius, r, g, b, attenuation){ if ((_AN_Read_length('length', this.lights)) < this.getMaxLights()) { var light = null ; if ((_AN_Read_length('length', this.lightPool)) > 0) { light = this.lightPool.pop(); light.set(x, y, z, radius, r, g, b, attenuation); } else { light = new Light(x, y, z, radius, r, g, b, attenuation); } this.lights.push(light); return light; } return null ; } , removeLight: function (light){ var index = this.lights.indexOf(light); if (index >= 0) { this.lightPool.push(light); this.lights.splice(index, 1); } } , updateLights: function (renderer, camera, shader){ } } ); module.exports = LightLayer;