Skip to content

Instantly share code, notes, and snippets.

@jpleau
Created June 15, 2013 05:50
Show Gist options
  • Save jpleau/5787082 to your computer and use it in GitHub Desktop.
Save jpleau/5787082 to your computer and use it in GitHub Desktop.
for (unsigned int i = 0; i < dimensions.x; ++i) {
for (unsigned int j = 0; j < dimensions.y; ++j) {
Tile tile = tiles[i + j * dimensions.x];
if (tile.hasChanged()) {
sf::Vertex *quad = &vertices[(i + j * dimensions.x) * 4];
quad[0].position = sf::Vector2f(i * block_size, j * block_size);
quad[1].position = sf::Vector2f((i + 1) * block_size, j * block_size);
quad[2].position = sf::Vector2f((i+1) * block_size, (j+1) * block_size);
quad[3].position = sf::Vector2f(i * block_size, (j+1) * block_size);
sf::FloatRect textureRect = sf::FloatRect(tile.getTileType().getTextureRect());
quad[0].texCoords = sf::Vector2f(textureRect.left, textureRect.top);
quad[1].texCoords = sf::Vector2f(textureRect.left + textureRect.width, textureRect.top);
quad[2].texCoords = sf::Vector2f(textureRect.left + textureRect.width, textureRect.top + textureRect.height);
quad[3].texCoords = sf::Vector2f(textureRect.left, textureRect.top + textureRect.height);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment