2014-05-23 30 views
1

我正在使用libgdx和box2d進行簡單的拖放式遊戲。 在桌面上,它運行良好,物體的運動流暢,但在Android(Galaxy SIII)上是對象和輸入之間的延遲,所以對象不在該點上,輸入已創建。libGDX拖放非常慢

在桌面上,一切就OK了:

enter image description here

在Android上,延遲:

enter image description here

的代碼很簡單,所以我不明白,爲什麼它不是工作.. 。

Character= new Texture(Gdx.files.internal("Character.jpg")); 
cam = new OrthographicCamera(); 
     cam.setToOrtho(false, 480, 800); 

    dx.input.setInputProcessor(this); 
    public void render(float delta) { 
     // TODO Auto-generated method stub 
     Gdx.gl.glClearColor(0.128f,0.128f,0.128f,1); 
     Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); 
     game.batch.setProjectionMatrix(cam.combined); 

     game.batch.begin(); 
     game.batch.draw(Character, object.x, object.y); 

     game.batch.end(); 
     cam.update(); 



    @Override 
    public boolean touchDragged(int screenX, int screenY, int pointer) { 
     // TODO Auto-generated method stub 
     Vector3 touchPos = new Vector3(); 
     touchPos.set(screenX, screenY, 0); 
     cam.unproject(touchPos); 


     object.x = touchPos.x - 56/2; 
     object.y=touchPos.y-56/2; 


     cam.update(); 

     return false; 
    } 

Wit hout libGdx的拖放運動效果更好。但libGdx是其他遊戲功能所必需的...

有人得到了一個建議? 問候

+0

我有完全相同的問題,您是否找到解決方案? – magritte

+0

對不起,我沒有找到解決方案......但現在我認爲這是因爲你的屏幕刷新頻率爲60Hz。但是當你移動精靈時,每秒鐘超過60個像素,一些像素將被跳過。這就是爲什麼運動看起來「不均勻」...... –

回答

0

你檢查了FPS嗎? 它通常用於限制幀率的S3。 確保所有省電模式均已停用,達到60 FPS。

+0

60fps不變...幀率似乎被鎖定... –

1

通過在Android啓動器中設置config.touchSleepTime = 16;,我看到了輕微的改進。

public class AndroidLauncher extends AndroidApplication { 
    @Override 
    protected void onCreate (Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     AndroidApplicationConfiguration config = new AndroidApplicationConfiguration(); 
     config.useAccelerometer = false; 
     config.useCompass = false; 
     config.touchSleepTime = 16; 
     initialize(new SomeGame(), config); 
    } 
} 

但仍有一個明顯的滯後,但希望這有助於。

+0

謝謝,我會試試看 - –

+0

終於嘗試過......不工作): –