Skip to content

Instantly share code, notes, and snippets.

@mishazawa
Last active November 15, 2018 11:44
Show Gist options
  • Select an option

  • Save mishazawa/ae453536534c275b11c9b76ce2262320 to your computer and use it in GitHub Desktop.

Select an option

Save mishazawa/ae453536534c275b11c9b76ce2262320 to your computer and use it in GitHub Desktop.
1d array vs 2d array
// 1d array
for (int i = 0; i < array.size(); i++) {
int row = i / mapWidth;
int column = i % mapWidth;
drawImage (column * tileWidth, row * tileHeight);
}
// 2d array
for (int x = 0; x < array.size(); x++) {
for (int y = 0; y < array[x].size(); y++) {
drawImage(x * tileWidth, y * tileHeight)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment