Advertisement
Guest User

LineStyle with Scale

a guest
Mar 21st, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haxe 2.27 KB | None | 0 0
  1. package;
  2. import openfl.display.Sprite;
  3. import openfl.display.Shape;
  4. import openfl.geom.Matrix;
  5. import openfl.display.Bitmap;
  6. import openfl.display.BitmapData;
  7.  
  8. class Main extends Sprite
  9. {
  10.     static private var coords : Array<Float> = [ 100, 100, 200, 100, 200, 200, 150, 200, 150, 150, 180, 150, 180,
  11.         120, 120, 120, 120, 150, 150, 150, 150, 200, 100, 200, 100, 100 ];
  12.     static var holeIn : Int = 4;
  13.     static var holeOut : Int = 10;
  14.    
  15.     public function new () {
  16.         super ();
  17.  
  18.        
  19.         var s = new Shape();
  20.         var s2 = new Shape();
  21.         var g = s.graphics;
  22.         var g2 = s2.graphics;
  23.         g.lineStyle( 1.0, 0, 1.0 ,true,openfl.display.LineScaleMode.NONE);
  24.         g.beginFill( 0x00ccbb, 1.0 );
  25.         g.moveTo( coords[0], coords[1] );
  26.        
  27.         g2.lineStyle( 1.0, 0, 1.0 ,true,openfl.display.LineScaleMode.NONE);
  28.         g2.beginFill( 0x00ccbb, 1.0 );
  29.         g2.moveTo( coords[0], coords[1] );
  30.         var i = 2;
  31.         while ( i < coords.length ) {
  32.             if ((i == holeIn * 2) || (i == holeOut * 2)) {
  33.                 g.lineStyle(null, 0, 0);
  34.                 g.lineTo( coords[i], coords[i + 1] );
  35.                 g.lineStyle( 1.0, 0, 1.0, true, openfl.display.LineScaleMode.NONE);
  36.                
  37.                 g2.lineStyle(null, 0, 0);
  38.                 g2.lineTo( coords[i], coords[i + 1] );
  39.                 g2.lineStyle( 1.0, 0, 1.0 , true,openfl.display.LineScaleMode.NONE);
  40.  
  41.             } else {
  42.                 g.lineTo( coords[i], coords[i + 1] );
  43.                 g2.lineTo( coords[i], coords[i + 1] );
  44.             }
  45.             i += 2;
  46.            
  47.         }
  48.         g.endFill();
  49.         g2.endFill();
  50.  
  51.        
  52.        
  53.         //display 1st as vector
  54.         addChild( s );
  55.        
  56.        
  57.        
  58.         //display 2nd as bitmap scaled down with matrix
  59.         var sc = 0.25;
  60.         var m = new Matrix();
  61.         m.scale(sc, sc);
  62.        
  63.         var bmd = new BitmapData(500, 500,true,0xFFFFFF);
  64.         bmd.draw(s,m);
  65.         var bm = new Bitmap(bmd, openfl.display.PixelSnapping.ALWAYS, false); // , openfl.display.PixelSnapping.AUTO, false);
  66.         bm.x = 300;
  67.         addChild(bm);
  68.        
  69.        
  70.         //display 3rd as vector scaled down
  71.         s2.scaleX = s2.scaleY = sc;
  72.         s2.x = 400;
  73.         addChild(s2);
  74.        
  75.  
  76.         //display 4rd as bitmap from scaled down vector (different behaviour in html and flash)
  77.         var bmd2 = new BitmapData(500, 500, true, 0xFFFFFF);
  78.         bmd2.draw(s2);
  79.         var bm2 = new Bitmap(bmd2, openfl.display.PixelSnapping.ALWAYS, false); // , openfl.display.PixelSnapping.AUTO, false);
  80.         bm2.x = 500;
  81.         addChild(bm2);
  82.  
  83.     }
  84.  
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement