【发布时间】:2014-08-16 02:27:00
【问题描述】:
最近,我一直在尝试改善游戏中的一些延迟问题,我这样做的一种方法是删除任何不必要的渲染。
这是我的TileMap 类中的render() 方法,它处理创建、更新和渲染游戏地图。
public void render(Graphics2D g) {
for(int row = 0; row < numRows; row++) {
for(int col = 0; col < numCols; col++) {
if(map[row][col] == 0) continue;
int rc = map[row][col];
int r = rc / numTilesAcross;
int c = rc % numTilesAcross;
g.drawImage(tiles[r][c].getImage(), x + (col * tileSize) - 8, y + (row * tileSize) - 8, null);
}
}
}
我一直在尝试这样的事情:
if(x + (col * tileSize) - 8 < x + (col * tileSize) - 8 + Panel.WIDTH) continue;
Panel.WIDTH 是窗口的宽度。我不太确定需要什么算法来测试越界渲染。
检查图块是否在屏幕左侧,但这不起作用。
我还认为循环遍历所有行和列可能会很慢,我想对其进行更改,使其仅循环可在屏幕上呈现的图块数量。
【问题讨论】: