在我的游戏中,我从服务器下载图像并使用它创建拼图。这意味着我必须使用alpha通道。然后我使用以下代码在屏幕上绘制这个拼图。 clusters数组有近300个要绘制的项目,它们在游戏开始时初始化。
问题是这个循环的性能在不同屏幕尺寸的不同Android设备上有所不同。这意味着我无法在大多数情况下获得足够好的帧速率。
设备1 (LG leon手机:480x800像素,220 ppi)
循环在25-30毫秒内运行
设备2 (三星Galaxy Tab A 7.0:800x1280像素,216 ppi)
循环在50-60毫秒内运行
如何为我的方案获得一致的性能或至少足够好的性能。
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`
答案 0 :(得分:0)
最好在服务器上调用图像以获取设备尺寸。 例如,全屏背景图像的大小必须为
在ldpi文件夹中,建议的大小为240x320。
在mdpi-folder中,建议的大小为320x480。
在hdpi文件夹中,建议的尺寸为480x800 ......
取决于设备屏幕尺寸。比在运行时缩放图像更好。