Advertisement
Guest User

Untitled

a guest
Aug 24th, 2015
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haxe 2.60 KB | None | 0 0
  1. package;
  2.  
  3. import openfl.display.Sprite;
  4. import openfl.Lib;
  5.  
  6. class Main extends Sprite {
  7.  
  8.     public function new() {
  9.         super();
  10.        
  11.         function loadBitmapData( name:String, ut:Bool, tc:UInt ) {
  12.             var bd = openfl.Assets.getBitmapData( name );
  13.             var target = new openfl.display.BitmapData( bd.width, bd.height );
  14.             if ( ut ) {
  15.                 for ( y in 0 ... bd.height ) {
  16.                     for ( x in 0 ... bd.width ) {
  17.                         var pix:UInt = bd.getPixel32( x, y );
  18.                         if ( pix == tc ) {
  19.                             target.setPixel32( x, y, 0 );
  20.                         } else {
  21.                             target.setPixel32( x, y, pix );
  22.                         }
  23.                     }
  24.                 }
  25.                 return target;
  26.             } else {
  27.                 return bd;
  28.             }
  29.         }
  30.        
  31.         var bm = loadBitmapData( 'img/bigfont.png', true, 0xffff0080 )
  32.         var ts = new openfl.display.Tilesheet( bm );
  33.         var w = 18; var h = 21;
  34.         for ( y in 0 ... Std.int( bm.height / h ) ) {
  35.             for ( x in 0 ... Std.int( bm.width / w ) ) {
  36.                 ts.addTileRect( new openfl.geom.Rectangle( x * w, y * h, w, h ) );
  37.             }
  38.         }
  39.        
  40.         inline function mergeBData( first:openfl.display.BitmapData, second:openfl.display.BitmapData ) {
  41.             first.copyPixels( second, new openfl.geom.Rectangle( 0, 0, second.width, second.height ), new openfl.geom.Point( 0, 0 ), second );
  42.         }
  43.        
  44.         var back = loadBitmapData( 'img/back.png', false, 0 );
  45.        
  46.         mergeBData( back, loadBitmapData( 'img/dt.png', true, 0xffff0080 ) );
  47.        
  48.         function drawText( g, text ) {
  49.             var x = 10, y = 10;
  50.             var r:Array<Float> = [];
  51.             for ( i in 0 ... text.length ) {
  52.                 x += w;
  53.                 r.push( x );
  54.                 r.push( y );
  55.                 r.push( text.charCodeAt( i ) );
  56.             }
  57.            
  58.             ts.drawTiles( g, r );
  59.         }
  60.        
  61.         stage.addEventListener( openfl.events.Event.ENTER_FRAME, function ( e:openfl.events.Event ) {
  62.             graphics.beginFill( 0xff44aaff );
  63.             graphics.drawRect( 0, 0, stage.stageWidth, stage.stageHeight );
  64.             graphics.endFill();
  65.            
  66.             graphics.beginBitmapFill( back );
  67.             graphics.drawRect( 0, 0, stage.stageWidth, stage.stageHeight );
  68.             graphics.endFill();
  69.             drawText( graphics, "Hello world! 123455677890 !@#$%^&*()" );
  70.         } );
  71.     }
  72.  
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement