我正在使用 javascript、CSS 和 HTML 绘制一个屏幕,方法是使用 for 循环以 16X16 的间隔遍历屏幕宽度和高度。这是我的循环当前的样子:
{
div = document.getElementById('mainView');
while (div.children.length > 0)
div.removeChild(div.children[0]);
for (y = this.y; y < this.y + this.height; ++y)
{
for (x = this.x; x < this.x + this.width; ++x)
{
toAppend = document.createElement('div');
viewCoords = this.convertWorldToView(x, y);
toAppend.style.top = viewCoords[1] * 16 + 'px';
toAppend.style.left = viewCoords[0] * 16 + 'px';
mainViewDiv.appendChild(toAppend);
if (fullMap[y][x] == TILE_WATER)
{
startTile = Math.round(Math.random() * 3) + 1;
toAppend.className = "Water" + startTile + "Tile";
}
else
{
toAppend.className = typeClassDecoder[fullMap[y][x]];
}
}
}
}
有没有更快的方法使用画布或javascript中的某些功能或javascript和css的混合将所有这些图块绘制到屏幕上?