【发布时间】:2014-01-24 10:03:46
【问题描述】:
我正在编写一个 Android 应用程序。我正在使用 Canvas,并通过使用 for 循环在其上绘制 Tilemap,并一个接一个地绘制每个图块。
我想通过渲染这个 tilemap(前景和背景个体)一次并保存它来提高性能,这样我就可以绘制整个地图而无需循环抛出每个瓦片。
我的图形类如下所示:
public class AGraphics implements Graphics {
Bitmap frameBuffer;
Canvas canvas;
Paint paint;
...
public AGraphics(.., Bitmap frameBuffer) {
this.frameBuffer = frameBuffer;
this.canvas = new Canvas(frameBuffer);
this.paint = new Paint();
}
...
public void drawPixmap(...){
canvas.drawBitmap(((AndroidPixmap) pixmap).bitmap, ... );
}
...
}
My World Class 调用 draw Pixmap 函数来绘制每个图块:
public class World {
...
public void drawForeground (float posX, float posY){
// get Graphics ...
for (int y = 0; y < map.height; y++) {
for (int x = 0; x <map.width; x ++) {
// calculate Positions
g.draw(tileset, (int)posX, (int)posY, srcX, srcY, tilesize, tilesize);
}
}
}
...
}
现在我正在寻找一种方法来保存画布并在每个 GameLoop 的不同位置重新绘制它以提高性能。
有什么想法或最佳实践吗?如果您需要更多信息,请询问!
谢谢
【问题讨论】:
标签: java android buffer android-canvas tile