在我的游戏中,我从服务器下载图像并使用它创建一个谜题。这意味着我必须使用 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`