问题
I am currently testing out all the features that a need in my game on the Android platform. I have only modified the hello-gl2 sample code, and added some textures, VBO's, FBO's and simple shaders in two rendering passes.
The thing is that when I let the app run with out touching the screen, i have about 35-45 fps. But if I start touching the screen continuously, the rendering starts to lag! So is this a problem because input and rendering is in the same thread (as a thinks it is?), is it even possible to fix? If I can't fix that lag, my game is probably not going to run good enough to bee playable. (Is has some heavy rendering stuff)
//Thanks in advance!
回答1:
I'm fairly new to android development but found the touch handler to be very laggy also. The default sample is newing up an object and doing this quite a lot - this is bound to make the garbage collector angry. I managed to get it to perform in a less laggy way by calling 'Thread.sleep(10);' inside the run function.
I imagine that replacing the 'new Runnable' with a circular buffer of objects would improve performance but I haven't investigated this yet. I'm the touch events seem to occur on a seperate thread and this may cause complications.
Override public boolean onTouchEvent(final MotionEvent event)
{
queueEvent(
new Runnable()
{
public void run()
{
int action = event.getAction();
//do your handling here
try
{
Thread.sleep(10);
} catch (InterruptedException e)
{
e.printStackTrace();
}
}
});
return true;
}
来源:https://stackoverflow.com/questions/5237414/android-opengl-lag-in-jni-when-touching-screen