b2Body.setPosition
Place body to x, y.
Syntax
setPosition(x, y)
Example
// create world this._world = new b2World(0.0, 9.8, false, true); // change gravity additionaly this.img = Bitmap.fromFile("app://img.png"); var shape = b2PolygonShape.fromRect(this.img.width, this.img.height); // create body this._bodyA = this._world.createBody(shape, #dynamic/*type of body*/, 0.9 /*density*/, 0.3/*friction*/, 0.03/*bounce*/); this._bodyA.setPosition(100, 50); // draw body this._bodyA.onDraw = function(sender, g) { var (left, top) = sender.getPosition(); var angleRad = sender.getAngle(); g.save(); g.translate(left, top); g.rotate(-(angleRad * 180.0 / Math.PI)); // rad2deg var matrix = new Matrix(); matrix.preTranslate(0, 0).preRotate(0).preTranslate(-this super.img.width/2, -this super.img.height/2); g.drawBitmapMatrix(this super.img, matrix); g.restore(); }
Parameters
x : Float | - The world position (x) of the body's local origin.
Y : Float | - The world position (y) of the body's local origin.
Returns
Returns type:
b2Body
Defined in
b2Body