Hi,
i try to start use Box2D and need some help:
1. set camera like this:
2. set world:
3. create ground:
4. create Dynamic body
5. try applyLinearImpulse Y
6. add text
I wanted it to look the same on different screens
questions:
- what am I doing wrong?
- body is very large?(falls slowly)
if i do Scale = 10 its ok, but i cant draw bitmapfont(rly big)
- very large pulse value, is it ok ?
i try to start use Box2D and need some help:
1. set camera like this:
B4X:
Dim Scale As Int = 100
Sub LG_Resize(Width As Int, Height As Int)
Camera.Initialize2( Scale * 4, Scale * 4 * Height / Width)
Camera.Position.set(0, Scale, 0)
End Sub
B4X:
Dim vGravity As lgMathVector2
World.Initialize(vGravity.set(0, -300), True, "World")
World.SetContinuousPhysics(True)
World.SetWarmStarting(True)
3. create ground:
B4X:
Dim bd As lgBox2DBodyDef
Dim ground As lgBox2DBody = World.createBody(bd)
Dim edgShape As lgBox2DEdgeShape
Dim V1, V2 As lgMathVector2
edgShape.set(V1.set(-190, 0), V2.set(190, 0))
ground.createFixture2(edgShape, 0)
edgShape.dispose
4. create Dynamic body
B4X:
Dim circle As lgBox2DCircleShape
circle.Radius = 10
Dim circleShapeDef As lgBox2DFixtureDef
circleShapeDef.shape = circle
circleShapeDef.Density = 1
circleShapeDef.restitution = 0.2
Dim circleBodyDef As lgBox2DBodyDef
circleBodyDef.Type = World.BODYTYPE_Dynamic
circleBodyDef.position.set(0, 100)
CI = World.createBody(circleBodyDef)
CI.createFixture(circleShapeDef)
circle.dispose
5. try applyLinearImpulse Y
B4X:
CI.applyLinearImpulse2(0,100000,CI.WorldCenter.x,CI.WorldCenter.y,True)
6. add text
B4X:
bitfont = FG.CreateFont("font1.ttf", 10dip,"TEX")
Dim Str As String = "TEXT"
bitfont.Draw(Batch, Str,Camera.Position.x-(bitfont.GetBounds(Str).Width/2),Camera.Position.y+(bitfont.GetBounds(Str).Height/2))
I wanted it to look the same on different screens
questions:
- what am I doing wrong?
- body is very large?(falls slowly)
if i do Scale = 10 its ok, but i cant draw bitmapfont(rly big)
- very large pulse value, is it ok ?