SHARE
TWEET

Untitled

a guest Oct 11th, 2017 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package;
  2. import flixel.FlxG;
  3. import flixel.FlxSprite;
  4. import flixel.util.FlxColor;
  5. import openfl.geom.Rectangle;
  6.  
  7. /**
  8.  * ...
  9.  * @author ORL
  10.  */
  11. class LightManager extends FlxSprite
  12. {
  13.     private var _maincol:Int;
  14.     private var _lights:Array<Light>;
  15.     public static var RESOLUTION:Int = 8;//4
  16.  
  17.     public function new(mainColor:Int = FlxColor.BLACK)
  18.     {
  19.         super(0, 0);
  20.         _maincol = mainColor;
  21.         makeGraphic(Std.int(FlxG.width/RESOLUTION), Std.int(FlxG.height/RESOLUTION), _maincol);
  22.         scrollFactor.x = scrollFactor.y = 0;
  23.         blend = openfl.display.BlendMode.MULTIPLY;
  24.        
  25.         width = width * RESOLUTION;
  26.         height = height * RESOLUTION;
  27. scale.x = scale.y = RESOLUTION;
  28.  
  29. centerOffsets();
  30. screenCenter();
  31.         antialiasing = false;
  32.        
  33.         _lights = [];
  34.     }
  35.  
  36.     override public function update(elapsed:Float):Void
  37.     {    
  38.         // Clear the canvas to a default state.
  39.         graphic.bitmap.lock();
  40.         graphic.bitmap.fillRect( new Rectangle(0, 0,  Std.int(FlxG.width/RESOLUTION), Std.int(FlxG.height/RESOLUTION)), FlxColor.fromRGB(0, 0, 0, 255));
  41.         graphic.bitmap.unlock();
  42.  
  43.         //Add lights
  44.         for (_light in _lights)
  45.         {
  46.             _light.update(FlxG.elapsed);//force update because lights are not attached to the stage
  47.    
  48.             if (_light.alive&&_light.enabled)
  49.             {
  50.                 //stamp supports only Int coordinates so I'm trying to put it in the best position (needs to be reviewed)
  51.                 stamp(_light, Math.round(Math.floor(_light.getXY().x * 10) / 10 / RESOLUTION), Math.round(Math.floor(_light.getXY().y * 10) / 10 / RESOLUTION));
  52.             }
  53.         }
  54.        
  55.         super.update(elapsed);
  56.     }
  57.  
  58.     public function addLight(light:Light):Void {
  59.         _lights.push(light);
  60.     }
  61.    
  62.     override public function destroy():Void
  63.     {
  64.     //  trace("destroy");
  65.         for (_light in _lights)
  66.         {
  67.             _light.destroy();
  68.         }
  69.        
  70.         super.destroy();
  71.     }
  72.  
  73. }
RAW Paste Data
Top