2

I am developing a small game using Haxe and box2d. I am rescaling the player body which is a sphere, while the player is in contact with a particular object, but I am trying to scale the image as I scale the body.

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

There is nothing that I know of that is built in to easily scale images. How can I scale the bitmap alongside the body?

user1989292
  • 43
  • 1
  • 1
  • 6
  • http://stackoverflow.com/questions/16273440/haxe-nme-resizing-a-bitmap/16274055#16274055 – Sergey Miryanov May 08 '13 at 07:47
  • I have tried using that code, but the program simply errors out when it tries to resize. I think the problem has to do with the source.bitmapData. I replaced that with new Bitmap(Assets.getBitmapData("img/Glob.png")) – user1989292 May 08 '13 at 09:12

1 Answers1

2

Why not just scale the imgSprite container?

imgSprite.scaleX = scale;
imgSprite.scaleY = scale;
Allan
  • 3,339
  • 2
  • 21
  • 24