2013-04-29 6 views
0

작은 게임을 만들기 위해 haxe로 NME를 배우려고합니다. FlashDevelop에서 Haxe 2.10으로 NME 3.5.5를 설정했습니다. 게임 배경을 그리려면Haxe NME 비트 맵 크기 조정

// 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(); 

이보기를 통해 이미지를 그리기 때문에 화면에 맞게 이미지의 크기를 조정해야합니다.

EDIT : 여기

내가 비트 맵을 사용하고 확장 기능이다. 작동하지 않고 화면에 아무 것도 렌더링되지 않습니다.

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); 
} 

답변

1

봐이 Resizing BitmapData in ActionScript 3

당신은하여 BitmapData.draw 및 스케일링 행렬을 사용해야합니다.

+0

그 것으로서 시도했습니다. 이제는 전혀 렌더링되지 않습니다. –

+0

이 메서드를 사용하면 모든 것이 잘 동작합니다. 최소한의 편집 가능한 예제를 보여줄 수 있습니까? 또한 스테이지에 비트 맵을 추가하지 않는 이유는 무엇입니까? 왜 beginBitmapFill로 그릴 수 있습니까? – W55tKQbuRu28Q4xv

+0

저는 실제로 자바로 만든 기존 게임을 Haxe로 포팅하고 있습니다. 보통 대용량의 자산을 가지고 있으며 사용자의 화면 크기에 따라 수동으로 크기를 조정합니다. 모든 객체가 애니메이션화되어야하고 스테이지에 추가 된 비트 맵을 변경할 수 없으므로이를 스프라이트 인 게임 클래스에 그려 넣습니다. –