2013-07-02 50 views
1

我正在使用MouseJoint拖動對象。但是物體的移動太慢了。LibGDX - Box2D:使用MouseJoint移動沒有速度限制的對象

enter image description here

我需要將它們與鼠標的速度移動。目前,我用MouseJointDef這些設置:

MouseJointDef def = new MouseJointDef(); 
def.bodyA = groundBody; 
def.bodyB = hitBody; 
def.collideConnected = true; 
def.target.set(testPoint.x, testPoint.y); 
def.maxForce = 10000.0f * hitBody.getMass(); 
def.frequencyHz=100; 
def.dampingRatio=0; 

這些一個身體:

Body box = world.createBody(def); 
MassData mass = new MassData(); 
mass.mass=100; 
//mass.I=1; What is it??? 
mass.center.set(width/2, height/2); 
box.setMassData(mass); 

我該怎麼辦?

回答

2

如果你的遊戲的寬度和高度過大,像800×480或東西,然後通過40像... 20x12把它....

這是因爲Box2D的速度被限制爲2個單位。並且你想要的是每個時間步數更多的單位,但是你的屏幕太大以至於無法實現...所以如果你縮短了你的世界,那麼速度問題將得到解決。

+1

我的錯誤是我用'this.cam.setToOrtho(false,Gdx.graphics.getWidth(),Gdx.graphics.getHeight());'在用正確的參數創建相機實例之後! :) 謝謝 – Nolesh