Skip to content

Instantly share code, notes, and snippets.

@andyhd
Created April 18, 2012 08:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save andyhd/2412173 to your computer and use it in GitHub Desktop.
Save andyhd/2412173 to your computer and use it in GitHub Desktop.
render with one loop
function drawMap(map) {
var i, x, y, height, pos,
width = map[0].length,
total_nodes = map.length * width;
for (i = 0; i < total_nodes; i++) {
x = i % width;
y = Math.floor(i / width);
height = {
top: map[y][x],
right: map[y][x+1],
bottom: map[y+1][x+1],
left: map[y+1][x]
};
pos = {
x: x,
y: y
};
drawTile(pos, height);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment