Search code examples
javaandroidcocos2d-android

Framedrops with Cocos2d-android when the game activity resumes


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();
    }
}

Solution

  • Ok fixed it. Apparently I forgot to call resume() on the director. Added this to the above code and it works fine:

    @Override
    public void onResume() {
        super.onResume();
        CCDirector.sharedDirector().resume();
    }