Developer   API   Game Development   Box2D   Native   b2Body   setPosition

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
API Navigation
Skip Navigation Links.
Expand <span>User Interface</span> User Interface
Expand <span>Core & System</span> Core & System
Expand <span>Graphics</span> Graphics
Expand <span>Files and Databases</span> Files and Databases
Expand <span>Crypto</span> Crypto
Expand <span>Native User Interface</span> Native User Interface
Expand <span>Net</span> Net
Expand <span>Media</span> Media
Expand <span>Sensor</span> Sensor
Collapse <span>Game Development</span> Game Development
Collapse <span>Box2D</span> Box2D
Collapse <span>Native</span> Native
b2World
b2Body
b2Contact
b2CircleShape
b2PolygonShape
b2DistanceJoint
b2FrictionJoint
b2GearJoint
b2MouseJoint
b2PrismaticJoint
b2PulleyJoint
b2RevoluteJoint
b2WeldJoint
PhysicsWorld
PhysicsBody
PhysicsContact
PhisicsScene
PhisicsSprite
Expand <span>Animation</span> Animation
Expand <span>Game2D</span> Game2D
Expand <span>Particle System</span> Particle System
Expand <span>Scene Transition</span> Scene Transition
Game
Canvas
Bitmap
Paint