Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package;
- import openfl.display.Sprite;
- import openfl.Lib;
- class Main extends Sprite {
- public function new() {
- super();
- function loadBitmapData( name:String, ut:Bool, tc:UInt ) {
- var bd = openfl.Assets.getBitmapData( name );
- var target = new openfl.display.BitmapData( bd.width, bd.height );
- if ( ut ) {
- for ( y in 0 ... bd.height ) {
- for ( x in 0 ... bd.width ) {
- var pix:UInt = bd.getPixel32( x, y );
- if ( pix == tc ) {
- target.setPixel32( x, y, 0 );
- } else {
- target.setPixel32( x, y, pix );
- }
- }
- }
- return target;
- } else {
- return bd;
- }
- }
- var bm = loadBitmapData( 'img/bigfont.png', true, 0xffff0080 )
- var ts = new openfl.display.Tilesheet( bm );
- var w = 18; var h = 21;
- for ( y in 0 ... Std.int( bm.height / h ) ) {
- for ( x in 0 ... Std.int( bm.width / w ) ) {
- ts.addTileRect( new openfl.geom.Rectangle( x * w, y * h, w, h ) );
- }
- }
- inline function mergeBData( first:openfl.display.BitmapData, second:openfl.display.BitmapData ) {
- first.copyPixels( second, new openfl.geom.Rectangle( 0, 0, second.width, second.height ), new openfl.geom.Point( 0, 0 ), second );
- }
- var back = loadBitmapData( 'img/back.png', false, 0 );
- mergeBData( back, loadBitmapData( 'img/dt.png', true, 0xffff0080 ) );
- function drawText( g, text ) {
- var x = 10, y = 10;
- var r:Array<Float> = [];
- for ( i in 0 ... text.length ) {
- x += w;
- r.push( x );
- r.push( y );
- r.push( text.charCodeAt( i ) );
- }
- ts.drawTiles( g, r );
- }
- stage.addEventListener( openfl.events.Event.ENTER_FRAME, function ( e:openfl.events.Event ) {
- graphics.beginFill( 0xff44aaff );
- graphics.drawRect( 0, 0, stage.stageWidth, stage.stageHeight );
- graphics.endFill();
- graphics.beginBitmapFill( back );
- graphics.drawRect( 0, 0, stage.stageWidth, stage.stageHeight );
- graphics.endFill();
- drawText( graphics, "Hello world! 123455677890 !@#$%^&*()" );
- } );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement