0
我想疊加我在我的遊戲世界中創建的Box2d對象的紋理。但紋理的座標是錯誤的。紋理的x軸和y軸與世界上實際的物體位置非常遠。紋理沒有繪製Box2d的身體
這是代碼負責繪製紋理的行:
batch.draw(khumbtexture, bodyKhumb.getPosition().x ,bodyKhumb.getPosition().y);
結果是紋理是由(150150)的矢量的偏移量。我該如何解決?
我想疊加我在我的遊戲世界中創建的Box2d對象的紋理。但紋理的座標是錯誤的。紋理的x軸和y軸與世界上實際的物體位置非常遠。紋理沒有繪製Box2d的身體
這是代碼負責繪製紋理的行:
batch.draw(khumbtexture, bodyKhumb.getPosition().x ,bodyKhumb.getPosition().y);
結果是紋理是由(150150)的矢量的偏移量。我該如何解決?
Box2D使用米的座標系。您的批處理可能在屏幕座標中操作,或者您定義了其投影矩陣,這可能會在嘗試繪製Box2D座標時導致差異。 你可以發佈一些代碼來設置你的SpriteBatch嗎?
這是一種方法。 1.設置一個攝像頭 2.設置SpriteBatch使用相機來繪製的,而不是其自身的內部一個
// setup the camera. In Box2D we operate on a
// meter scale, pixels won't do it. So we use
// an orthographic camera with a viewport of
// 48 meters in width and 32 meters in height.
// We also position the camera so that it
// looks at (0,16) (that's where the middle of the
// screen will be located).
camera = new OrthographicCamera(48, 32);
camera.position.set(0, 15, 0);
然後在您的渲染方法
camera.update();
batch.setProjectionMatrix(camera.combined);
//clear screen here
//draw your stuff in Box2D meter coordinates
batch.draw(texture,1,2);
y ...試過了!...現在放棄在libgdx上說實話...只是不適合我! – whythehack 2012-04-04 13:06:22
如果你發佈一些代碼,它可以幫助 – 2012-04-04 17:54:57