0

小さなゲームを作成するために haxe で NME を学習しようとしています。FlashDevelop で Haxe 2.10 を使用して NME 3.5.5 をセットアップしました。ゲームの背景を描くために、私は使用しています

// Class level variable
var background : nme.display.Bitmap;

public function initResources() : Void
{
    background = new Bitmap(Assets.getBitmapData("img/back.png"));
}

レンダリング ループでは、このようにレンダリングしています。

g.clear();
g.beginBitmapFill(background.bitmapData, true, true);
g.drawRect(0, 0, 640, 480);
g.endFill();

これはビュー全体に画像を描画しているため、画面に合わせてサイズを変更する必要があります。

編集:

ビットマップのスケーリングに使用している関数は次のとおりです。機能せず、画面に何もレンダリングされません。

public static function resize( source:Bitmap, width:Int, height:Int ) : Bitmap
{
    var scaleX:Int = Std.int(width / source.bitmapData.width);
    var scaleY:Int = Std.int(height / source.bitmapData.height);
    var data:BitmapData = new BitmapData(width, height, true);
    var matrix:Matrix = new Matrix();
    matrix.scale(scaleX, scaleY);
    data.draw(source.bitmapData, matrix);
    return new Bitmap(data);
}

ありがとう。

編集2:

最後にそれを作った。不必要にintにキャストしていました。これが解決策です。

public static function resize( source:Bitmap, width:Int, height:Int ) : Bitmap
{
    var scaleX:Float = width / source.bitmapData.width;
    var scaleY:Float = height / source.bitmapData.height;
    var data:BitmapData = new BitmapData(width, height, true);
    var matrix:Matrix = new Matrix();
    matrix.scale(scaleX, scaleY);
    data.draw(source.bitmapData, matrix);
    return new Bitmap(data);
}
4

1 に答える 1

1

このResizing BitmapData in ActionScript 3 を見てください

BitmapData.draw とスケーリングされたマトリックスを使用する必要があります。

于 2013-04-29T08:16:04.977 に答える