【问题标题】:Improve Performance of drawBitmap and Frame rate of game thread (android)提高drawBitmap的性能和游戏线程的帧率(android)
【发布时间】:2023-03-30 19:03:01
【问题描述】:

我有一个绘制表面视图的游戏线程。它处理游戏变量,然后在画布上绘制。 board 是一个位图,将绘制在视图的画布上。 callDrawHelper 在板上重新绘制,第一个简单的 背景 图像(与板大小相同)。然后 clusters 列表根据游戏变量数据在画布上绘制一组图像。整个过程执行每一帧。

callDrawHelper 需要接近 80 毫秒,这是线程处理的最高组件。这也确实降低了帧速率。如何提高此代码段的性能。

protected void callDrawHelper() {

    Canvas gfx = drawJustBackground();
        for (int i = 0; i < clusters.size(); i++) {

            PieceCluster cluster = clusters.get(i);
            if (cluster.isVisible) {
                gfx.drawBitmap(cluster.Picture, cluster.BoardLocation.left,
                        cluster.BoardLocation.top, null);
            }
        }


}

 protected Canvas drawJustBackground() {
    Canvas gfx = new Canvas(board);
    gfx.drawBitmap(background, 0, 0, null);
    return gfx;
}

【问题讨论】:

    标签: android multithreading canvas frame-rate


    【解决方案1】:

    如果不进一步调查,很难说问题出在哪里。我将首先使用 Traceview 来分析 CPU 使用情况,如下所示:Android drawBitmap Performance For Lots of Bitmaps? 还要确保您的图像已经按照此处的建议进行了缩放:Improve performance of Canvas.drawBitmap() on android

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多