2017-05-07 2 views
0

Im은 Box2D 물리 엔진에 대해 배우려고합니다. Im LibGX에서 사용 중이며 문제가 발생했습니다. 당신은 규모 int를 사용하여 createDynamicBody에서LibGx Box2D 픽셀 대 측정기 만 큰 물체를 그립니다.

public class GameScreen implements Screen{ 
static int PPM = 100; 
Box2DDebugRenderer debugRenderer; 
World w = new World(new Vector2(0,-0.981f),true); 
OrthographicCamera cam; 

public static Body createDynamicBody(World world, int x, int y, int w, 
    int h, int density, int scale) { 
    BodyDef def = new BodyDef(); 
    def.type = BodyDef.BodyType.DynamicBody; 
    def.position.set(x/scale,y/scale); 
    Body b = world.createBody(def); 
    FixtureDef fdef =new FixtureDef(); 
    PolygonShape shape = new PolygonShape(); 
    shape.setAsBox((w/2)/scale,(h/2)/scale); 
    fdef.shape = shape; 
    b.createFixture(fdef); 
    return b; 
} 

// initialized when Screen is loaded 
@Override 
public void show() { 
    cam = new OrthographicCamera(); 
    font = new BitmapFont(); 
    debugRenderer = new Box2DDebugRenderer(); 
    cam.setToOrtho(false,800,480); 
    debugRenderer = new Box2DDebugRenderer(); 
    // this body is not drawn 
    Body b = createDynamicBody(w,200,200,150,150,5, PPM); 
    // this body is drawn 
    Body b2 = createDynamicBody(w,200,200,200,200,5, PPM); 
} 

@Override 
public void render(float delta) { 
    Gdx.gl.glClearColor(0.2f,0.1f,0.7f,1); 
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); 
    debugRenderer.render(w,camera.combined.cpy().scale(PPM,PPM,0)); 
    w.step(1/60f,6,2); 
} 

} 
+0

제발, 도와주세요 :/ – Liwaa

답변

0

: 내가 픽셀에서 미터로, 단지 큰 개체가 그려 변환 할 때 는 .. 이 말한다. 이것은 나누면 정밀도가 느슨해집니다. int 스케일을 float 스케일로 대체하면 효과가있다.

public static Body createDynamicBody(World world, int x, int y, int w, 
              int h, int density, float scale) 
+0

제발, PPM이 고정되어 있어야합니다. int가 아닙니다. – Liwaa

관련 문제