Posts tonen met het label Bitmap. Alle posts tonen
Posts tonen met het label Bitmap. Alle posts tonen

zaterdag 6 februari 2016

Haxe / Stencyl : Drawing shapes onto image

Haxe / Stencyl

Drawing stuff like lines, shapes, circles, rectangle on an image:

var shape = new nme.display.Shape();
var g = shape.graphics;
g.beginFill( 0xffffff );
g.lineStyle(1,0x000000);

g.drawRect(8,8,280,280);
g.moveTo(32,32);
g.lineTo(128,128);
g.endFill();
var bmp = new BitmapData(64,64,true, 0x00000000 );
bmp.draw(shape);
var b=new Bitmap(bmp);

attachImageToHUD(new BitmapWrapper(b), 0,0);

or:

bd = new BitmapData(Std.int(shapeWidth), Std.int(shapeHeight), true, 0);
var s = new Shape();
s.graphics.lineStyle(2, 204);
s.graphics.drawCircle(50, 50, 20);
bd.draw(s);
attachImageToHUD(new BitmapWrapper(new Bitmap(bd)), 0, 0);

donderdag 21 januari 2016

Haxe/Stencyl : Rotate Image

Stencyl lhas a block to spin the image instance, but then it is an instance instead of an image that we can upload.

This block code (Advanced -> Flow ) or Extension function can do the trick.

This is the code in an extension:




 public static function RotateImage(bitmapData:BitmapData):BitmapData{
                var degree=90;
                var newBitmap:BitmapData = new BitmapData( bitmapData.height, bitmapData.width, true );
                var matrix:Matrix = new Matrix();
                matrix.rotate( degree*(Math.PI/180) );
                if ( degree == 90 ) {
                        matrix.translate( bitmapData.height, 0 );
                } else if ( degree == -90 || degree == 270 ) {
                        matrix.translate( 0, bitmapData.width );
                } else if ( degree == 180 ) {
                        newBitmap = new BitmapData( bitmapData.width, bitmapData.height, true );
                        matrix.translate( bitmapData.width, bitmapData.height );
                }
                newBitmap.draw( bitmapData, matrix, null, null, null, true );
                return newBitmap;

        }