0

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

1 回答 1

0

最好在服务器上调用图像以获取设备尺寸。例如,全屏背景图像的大小必须为

在 ldpi-folder 中,推荐大小为 240x320。

在 mdpi-folder 中,推荐大小为 320x480。

在 hdpi 文件夹中,推荐大小为 480x800...

这取决于设备屏幕尺寸。比在运行时缩放图像更好。

于 2017-09-06T08:17:11.660 回答