0

In my game I download a image from server and create a puzzle using it. This means I have to use alpha channel. Then I draw this puzzle pieces on screen using following code. The clusters array has close to 300 items to draw, they are initialized at game start.

The issue is perfromance of this loop varies on different android devices with different screen sizes. Which means I cant get good enough frame rate most cases.

Device 1 (LG leon phone: 480x800 pixels, 220 ppi)

loop runs in 25-30 ms

Device 2 (Samsung Galaxy Tab A 7.0: 800x1280 pixels, 216 ppi)

loop runs in 50-60 ms

How can I get consistent performance or at least good enough performance for my scenario.

       canvas.scale(mScaleFactor, mScaleFactor);
        canvas.translate(mPosX, mPosY);

        long startTime = System.currentTimeMillis();

            for (int i = 0; i < game.clusters.size(); i++) {

                PieceCluster cluster = game.clusters.get(i);
                if (cluster.isVisible) {

                    canvas.drawBitmap(cluster.Picture, cluster.BoardLocation.left,
                           cluster.BoardLocation.top, canvasPaint);
                }
            }


    // this is paint object
    canvasPaint.setAntiAlias(true);
    canvasPaint.setFilterBitmap(true);
    canvasPaint.setDither(true);`enter code here`
pats
  • 1,273
  • 2
  • 20
  • 43

1 Answers1

0

Better you call images on your server for device dimension. As an example Full screen background images must sized as

In ldpi-folder, the recommended size is 240x320.

In mdpi-folder, the recommended size is 320x480.

In hdpi-folder, the recommended size is 480x800...

It depends on device screen size. Better than scaling image on run time.

mbakgun
  • 75
  • 5
  • thanks for your response. Downloaded image from server is scaled to screen size and down-sampled and then broken into 300 segments at the initialization of the game. There for I dont scale each image every frame. canvas.scale function is there to support zoom in and out feature. – pats Sep 06 '17 at 08:48