Advertisement
Guest User

Untitled

a guest
Feb 17th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haxe 3.29 KB | None | 0 0
  1.  private function getSprite(regionAttachment:RegionAttachment):FlxSprite
  2.     {
  3.         //if (Registry.PLAYER_1_CUSTOM_HEAD != 0)
  4.         //{
  5.             //trace("we picked head before, trying to set");
  6.             //Registry.PLAYER_1_CUSTOM_HEAD = 0;
  7.             //refresh = true;
  8.         //}
  9.        
  10.         if(refresh==false)
  11.         if (regionAttachment.wrapperSprite != null && Std.is(regionAttachment.wrapperSprite, FlxSprite))
  12.             return cast(regionAttachment.wrapperSprite, FlxSprite);
  13.        
  14.         //      trace("get sprite");
  15.                
  16.         var region:AtlasRegion = cast regionAttachment.rendererObject;
  17.         var graph:FlxGraphic = cast(region.page.rendererObject, FlxGraphic);
  18.        
  19.         var regionWidth:Float = region.rotate ? region.height : region.width;
  20.         var regionHeight:Float = region.rotate ? region.width : region.height;
  21.        
  22.         var atlasFrames:FlxAtlasFrames = (graph.atlasFrames == null) ? new FlxAtlasFrames(graph) : graph.atlasFrames;
  23.        
  24.         var name:String = region.name;
  25.         var offset:FlxPoint = FlxPoint.get(0, 0);
  26.         var frameRect:FlxRect = new FlxRect(region.x, region.y, regionWidth, regionHeight);
  27.        
  28.         var sourceSize:FlxPoint = FlxPoint.get(frameRect.width, frameRect.height);
  29.         var imageFrame = FlxImageFrame.fromFrame(atlasFrames.addAtlasFrame(frameRect, sourceSize, offset, name));
  30.        
  31.         if (regionAttachment.name.indexOf("alien/masks/custom") >=0)
  32.         {
  33.             var amountOfLevelsOnDisk:Int = 0;
  34.  
  35.          
  36.             var directory:String;
  37.  
  38.         //  if(Registry.USE_LOCAL_FOLDERS)
  39.             directory = "assets/custom heads/pack";
  40.         //  else
  41.         //  directory = "../../../../assets/custom heads/pack";
  42.  
  43.             files = new Array<String>();   
  44.            
  45.             if (FileSystem.exists(directory))
  46.             {
  47.                 trace("directory found: " + directory);
  48.                
  49.                 for (file in FileSystem.readDirectory(directory))
  50.                 {
  51.                     var path = Path.join([directory, file]);
  52.                    
  53.                     if (!FileSystem.isDirectory(path))
  54.                     {
  55.                         files.push(path);
  56.                     //  trace("file found: " + path);
  57.                     //  trace("files found");
  58.                         // do something with file
  59.                     }
  60.                     else
  61.                     {
  62.                         //var directory = Path.addTrailingSlash(path);
  63.                         //trace("directory found: " + directory);
  64.                         //recursiveLoop(directory);
  65.                     }
  66.                 }
  67.             }
  68.             else
  69.             {
  70.                 trace('"$directory" does not exists');
  71.             }
  72.    
  73.             trace("mask detected, replacing");
  74.             var wrapper2:FlxSprite = new FlxSprite("assets/custom heads/custom1.png");
  75.            
  76.             if (regionAttachment.name.indexOf("alien/masks/custom1") >=0)
  77.             wrapper2.loadGraphic("assets/custom heads/custom1.png");
  78.            
  79.             if (regionAttachment.name.indexOf("alien/masks/custom2") >=0)
  80.             wrapper2.loadGraphic("assets/custom heads/custom2.png");   
  81.            
  82.             if (regionAttachment.name.indexOf("alien/masks/custom3") >=0)
  83.             wrapper2.loadGraphic("assets/custom heads/custom3.png");
  84.        
  85.             if (regionAttachment.name.indexOf("alien/masks/custom4") >=0)
  86.             wrapper2.loadGraphic("assets/custom heads/custom4.png");
  87.            
  88.             if (refresh)
  89.             {
  90.                 if (regionAttachment.name.indexOf("alien/masks/custom1") >= 0)
  91.                 {
  92.                     trace("picked head " + files[Registry.PLAYER_1_CUSTOM_HEAD].toString());
  93.                    
  94.                     wrapper2.loadGraphic(files[Registry.PLAYER_1_CUSTOM_HEAD].toString());
  95.                 //  wrapper2.loadGraphic("assets/custom heads/pack/commandervideo.png");
  96.                 }
  97.             }
  98.             refresh = false;
  99.                
  100.             imageFrame = FlxImageFrame.fromGraphic(wrapper2.graphic);
  101.         }
  102.        
  103.         var wrapper:FlxSprite = new FlxSprite();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement