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`
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.