Advertisement
pol2095

Starling OpenFl mask sample

Oct 21st, 2017
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package;
  2.  
  3. import openfl.system.System;
  4.  
  5. //import scenes.Scene;
  6.  
  7. import starling.events.Event;
  8. import starling.display.Sprite;
  9. import starling.display.Quad;
  10. import starling.display.Canvas;
  11. import starling.display.Image;
  12. import starling.textures.Texture;
  13. import starling.extensions.TextureMaskStyle;
  14. import starling.utils.AssetManager;
  15.  
  16. @:keep class MainClass extends Sprite
  17. {    
  18.     private static var sAssets:AssetManager;
  19.    
  20.     public function new()
  21.     {
  22.         super();
  23.         // nothing to do here -- Startup will call "start" immediately.
  24.     }
  25.    
  26.     public function start(assets:AssetManager):Void
  27.     {
  28.         sAssets = assets;
  29.        
  30.         showMask();
  31.     }
  32.    
  33.     private function showMask():Void
  34.     {
  35.                // now would be a good time for a clean-up
  36.         #if 0
  37.         System.pauseForGCIfCollectionImminent(0);
  38.         #end
  39.         System.gc();
  40.        
  41.         var canvas:Canvas = new Canvas();
  42.         canvas.beginFill(0x00FF00);
  43.         canvas.drawCircle(100, 100, 100);
  44.         canvas.endFill();
  45.         this.addChild(canvas);
  46.        
  47.         var textures:openfl.Vector<Texture> = assets.getTextures("img_");
  48.         _mask = new Image( textures[1] );
  49.         //_mask = new Quad( 528, 110, 0 );
  50.         _mask.x = -484;
  51.        
  52.         var style:TextureMaskStyle = new TextureMaskStyle();
  53.         mask.style = style;
  54.         canvas.mask = mask;
  55.     }
  56.    
  57.     public static var assets(get, never):AssetManager;
  58.     @:noCompletion private static function get_assets():AssetManager { return sAssets; }
  59.    
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement