Constant FPS Android OpenGLES

后端 未结 2 815
星月不相逢
星月不相逢 2021-01-01 06:20

Hello android developers,

I am developing a simple game for Android in Eclipse using OpenGLES 1.0. I am using Samsung Galaxy S2 Android(2.3) as a device for developm

2条回答
  •  礼貌的吻别
    2021-01-01 06:58

    You should use elapsed time to scale all your movement, so that the movement stays smooth at varying FPS rates. You can get elapsed time like this:

    long currentTime = System.currentTimeMillis();
    float elapsed = (System.currentTimeMillis() - lastFrameTime) * .001f;//convert ms to seconds
    lastFrameTime = currentTime; 
    

    Then express your velocities in units per second, and update position like this:

    sprite.x += (sprite.xspeed * elapsed);
    

提交回复
热议问题