2017-05-07 5 views
0

ImはBox2D物理エンジンについて学んでいます。 私はLibGXでそれを使用していて、問題に直面しています。 私はピクセルからメートルに変換すると、唯一の大規模なオブジェクトが描画される。.. はこれを言う:あなたの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型を使用しています。これにより、分割するときに精度が失われてしまいます。 int型のスケールを浮動小数点のスケールに置き換えるだけで動作します。

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

は、PPMは..感謝をint型ではないフロートされている必要があり、それを修正するために管理:) – Liwaa

関連する問題