我正在努力学习NME与haxe创造一个小游戏。我已经在FlashDevelop中安装了带有Haxe2.10的NME3.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);
}发布于 2013-04-29 08:16:04
看这个Resizing BitmapData in ActionScript 3
您应该使用BitmapData.draw和缩放矩阵。
https://stackoverflow.com/questions/16273440
复制相似问题