java - Android game GLSurfaceView time handling -
i trying make small android game java , opengl es 2.0. trying create game loop smooth feeling if example objects moving. tried 4 approaches of them making me not happy.
here approaches:
approach 1:
@override public void ondrawframe(gl10 gl) {     game.update(1.0f / 60.0f);     game.render(); } result:
approximately 2 seconds there little lag/delay. between 2 seconds fells smooth.
approach 2:
@override public void ondrawframe(gl10 gl) {         newtime = system.currenttimemillis();         deltime = newtime - oldtime;         oldtime = newtime;          game.update(deltime / 1000.0f);         game.render(); } result:
approximately 2 seconds there little lag/delay, same "approach 1". between 2 seconds fells smooth.
approach 3:
@override public void ondrawframe(gl10 gl) {         newtime = system.currenttimemillis();         deltime = newtime - oldtime;         oldtime = newtime;         lagtime += deltime;          // 18ms ~ 55 frames per second         while(lagtime >= 18)         {             game.update(18 / 1000.0f);              lagtime -= 18;         }          game.render(); } result:
approximately 0.5 seconds there little lag/delay. feels never smooth.
approach 4:
@override public void ondrawframe(gl10 gl) {     newtime = system.currenttimemillis();     deltime = newtime - oldtime;     oldtime = newtime;     lagtime += deltime;      // 18ms ~ 55 frames per second     while(lagtime >= 18)     {         game.update(18 / 1000.0f);          lagtime -= 18;     }      // render linear interpolated dependent on lag time.     game.render(lagtime / 1000.0f); } result:
approximately 2 seconds there little lag/delay, same "approach 1" , "approach 2". between 2 seconds fells smooth.
summary:
i pretty sure not allocating memory gc have not work else cause these lags 2 seconds ?
and why glsurfaceview call "ondrawframe" method 60 times per second without do(sometimes 58 or 62 times per second, too) thought calls method can , 60 fps sounds not randomly possible specify rate , how behave on other devices?
so whats approach without lags 2 seconds simple 2d game fast moving objects(so 40-60 fps should minimum) ?
if important, tested approaches on nexus 7(2013) android 5.1.1.
ok, after few days trying fix problem found solution. take average delta time 5 frames. seems work better not perfect.
Comments
Post a Comment