当游戏活动恢复时,Cocos2d-android 出现帧丢失
我正在尝试一些适用于 android 的游戏引擎,并遇到了 cocos2d-android-1。 我设置了一个小示例,除了首先显示 FPS 计数器之外,它几乎什么也不做。
问题是,每次 Activity 进入后台(通过 home 或 back 键)并返回时,FPS 都会下降很多。第一次启动时,它们对我来说约为 60(HTC Desire),恢复活动后,它们保持在 10 以下。
该活动在清单中固定为横向,并使用 @android:style/Theme.Black.NoTitleBar.Fullscreen
启用全屏模式。
当我从设备设置中的应用程序菜单停止该应用程序时,它会重置所有内容。第一次发射再次达到 60 fps,下一次发射也会下降。
我该如何解决这个问题?
这是一个小的工作示例:
public class MainActivity extends Activity {
private CCGLSurfaceView glSurfaceView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
glSurfaceView = new CCGLSurfaceView(this);
setContentView(glSurfaceView);
}
@Override
public void onStart() {
super.onStart();
CCDirector.sharedDirector().attachInView(glSurfaceView);
CCDirector.sharedDirector().setDisplayFPS(true);
}
@Override
public void onPause() {
super.onPause();
CCDirector.sharedDirector().pause();
}
}
I'm trying out some game engines for android and came across cocos2d-android-1.
I've set up a small example that pretty much does nothing except to show a FPS counter to start with.
The problem is that every time the activity goes to the background (via the home or back key) and comes back, the FPS drop a lot. At the first start they are around 60 for me (HTC Desire), after resuming the activity they stay below 10.
The activity is fixed to landscape in the manifest and uses @android:style/Theme.Black.NoTitleBar.Fullscreen
to enable fullscreen mode.
When I stop the app from the applications menu in the device settings it resets everything. The first launch gets 60 fps again, next launch drops too.
How can I fix this?
Here is a small working sample:
public class MainActivity extends Activity {
private CCGLSurfaceView glSurfaceView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
glSurfaceView = new CCGLSurfaceView(this);
setContentView(glSurfaceView);
}
@Override
public void onStart() {
super.onStart();
CCDirector.sharedDirector().attachInView(glSurfaceView);
CCDirector.sharedDirector().setDisplayFPS(true);
}
@Override
public void onPause() {
super.onPause();
CCDirector.sharedDirector().pause();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,修好了。显然我忘记对导演调用resume()。
将其添加到上面的代码中,它工作正常:
Ok fixed it. Apparently I forgot to call resume() on the director.
Added this to the above code and it works fine: