2014-05-23 29 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

终于尝试过......不工作): –