Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package;
- import flixel.FlxG;
- import flixel.FlxSprite;
- import flixel.util.FlxColor;
- import openfl.geom.Rectangle;
- /**
- * ...
- * @author ORL
- */
- class LightManager extends FlxSprite
- {
- private var _maincol:Int;
- private var _lights:Array<Light>;
- public static var RESOLUTION:Int = 8;//4
- public function new(mainColor:Int = FlxColor.BLACK)
- {
- super(0, 0);
- _maincol = mainColor;
- makeGraphic(Std.int(FlxG.width/RESOLUTION), Std.int(FlxG.height/RESOLUTION), _maincol);
- scrollFactor.x = scrollFactor.y = 0;
- blend = openfl.display.BlendMode.MULTIPLY;
- width = width * RESOLUTION;
- height = height * RESOLUTION;
- scale.x = scale.y = RESOLUTION;
- centerOffsets();
- screenCenter();
- antialiasing = false;
- _lights = [];
- }
- override public function update(elapsed:Float):Void
- {
- // Clear the canvas to a default state.
- graphic.bitmap.lock();
- graphic.bitmap.fillRect( new Rectangle(0, 0, Std.int(FlxG.width/RESOLUTION), Std.int(FlxG.height/RESOLUTION)), FlxColor.fromRGB(0, 0, 0, 255));
- graphic.bitmap.unlock();
- //Add lights
- for (_light in _lights)
- {
- _light.update(FlxG.elapsed);//force update because lights are not attached to the stage
- if (_light.alive&&_light.enabled)
- {
- //stamp supports only Int coordinates so I'm trying to put it in the best position (needs to be reviewed)
- stamp(_light, Math.round(Math.floor(_light.getXY().x * 10) / 10 / RESOLUTION), Math.round(Math.floor(_light.getXY().y * 10) / 10 / RESOLUTION));
- }
- }
- super.update(elapsed);
- }
- public function addLight(light:Light):Void {
- _lights.push(light);
- }
- override public function destroy():Void
- {
- // trace("destroy");
- for (_light in _lights)
- {
- _light.destroy();
- }
- super.destroy();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement