0

I'm new in Android and I'm trying to write a simple game. This is the Main Thread game loop (very simple) that I use (I don't know if is this the problem):

    @Override
    public void run(){
        [...]

        while(running) {
            startTime = System.nanoTime();
            canvas = null;

            //try locking the canvas for pixel editing
            //update and draw GameObjects
            [...]

            timeMillis = (System.nanoTime() - startTime) / 1000000;
            waitTime = targetTime-timeMillis;

            try{
                this.sleep(waitTime);
            }catch(Exception e){}

            totalTime += System.nanoTime()-startTime;
            frameCount++;
            if(frameCount == FPS){
                averageFPS = 1000/((totalTime/frameCount)/1000000);
                frameCount =0;
                totalTime = 0;

                System.out.println(averageFPS);  //Testing
            }
        }

Now... The project use Android 4 API and I'm testing this game on OnePlus 5. When I upgrade my phone to Android 8, the FPS number has dropped dramatically. With Android 6 I can reach 62 FPS, now (with the SAME code) I can not exceed 13 FPS! Why? The problem is in my project or in Android? Can I fix it?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Calaf
  • 1,133
  • 2
  • 9
  • 22

1 Answers1

0

I solved the problem by removing canvas.scale (...) in the main method. I cannot explain why the FPS have dropped only after the update of Android Oreo.

Pang
  • 9,564
  • 146
  • 81
  • 122
Calaf
  • 1,133
  • 2
  • 9
  • 22