setAnimationInterval does nothing on Android

Well, I’ve managed to do it :slight_smile: I don’t know why, but when I uncommented the fps control part in Cocos2dxRenderer.java it didn’t work, but when I wrote it myself it does. The snippet below shows how it’s done, and the magic value of “40” gives about 35fps. Anyway it would be fairly easy to rig it to react to setAnimationInterval();

Don’t forget to rebuild cocos before testing!

public void onDrawFrame(final GL10 gl) {

         // FPS controlling algorithm is not accurate, and it will slow down FPS
         // on some devices. So comment FPS controlling code.

        loopStart = System.currentTimeMillis();

        try {
            if (loopRuntime < 40) {
                Log.wtf("RENDERER", "Sleeping for == " + (40 - loopRuntime));
                Thread.sleep(40 - loopRuntime);
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        //final long nowInNanoSeconds = System.nanoTime();
        //final long interval = nowInNanoSeconds - this.mLastTickInNanoSeconds;


        // should render a frame when onDrawFrame() is called or there is a
        // "ghost"
        Cocos2dxRenderer.nativeRender();

        loopEnd = System.currentTimeMillis();
        loopRuntime = (loopEnd - loopStart);

        Log.wtf("RENDERER", "loopRunTime == " + loopRuntime);

        // fps controlling
        /*if (interval < Cocos2dxRenderer.sAnimationInterval) {
            try {
                // because we render it before, so we should sleep twice time interval
                Thread.sleep((Cocos2dxRenderer.sAnimationInterval - interval) / Cocos2dxRenderer.NANOSECONDSPERMICROSECOND);
            } catch (final Exception e) {
            }
        }*/

        //this.mLastTickInNanoSeconds = nowInNanoSeconds;
}