2013-05-08 38 views
2

我正在开发一个使用Haxe和box2d的小游戏。当玩家与特定对象接触时,我正在重新缩放球体的球体,但是我在缩放身体时试图缩放图像。调整Haxe中的Sprite图像大小?

public function new(w:Int, x:Int, y:Int) 
{ 
    super(); 
    this.w = w; 
    this.x = x; 
    this.y = y; 
    var imgSprite = new Sprite(); 
    imgSprite.addChild(new Bitmap(Assets.getBitmapData("img/ball.png"))); 
    imgSprite.x = -w; 
    imgSprite.y = -w; 
    this.addChild(imgSprite); 
    this.alpha = .5; 
    contactList = new Array<B2Body>(); 
    makeBody(w, x, y, 0); 
} 

public function resize(w:Int, x:Int, y:Int) 
{ 
    var tempAngle = this.body.getAngle(); 
    Main.World.destroyBody(this.body); 
    makeBody(w, x, y, tempAngle); 
} 

没有什么,我知道这是内置的轻松缩放图像。我怎样才能缩放旁边的位图?

+0

http://stackoverflow.com/questions/16273440/haxe-nme-resizing-a-bitmap/16274055#16274055 – W55tKQbuRu28Q4xv 2013-05-08 07:47:16

+0

我一直在使用该代码尝试,但该程序只是出现了错误,当它试图调整。我认为这个问题与source.bitmapData有关。我用新的位图替换了它(Assets.getBitmapData(“img/Glob.png”)) – user1989292 2013-05-08 09:12:43

回答

2

为什么不按比例缩放imgSprite容器?

imgSprite.scaleX = scale; 
imgSprite.scaleY = scale;