I have this to draw a tile map:
sf::VertexArray va(sf::Quads, 10240);
int y = 0;
int x = 0;
sf::Texture sprite_sheet = sfml_resources::get().get_spritesheet();
int i = 0;
for(chunk c : m_game.get_loaded_chunks()){
for(tile t : c.get_tiles()){
y = (16 * (t.get_type() / 57)) / 16;
x = (17 * t.get_type()) % (57 * 17);
sf::Vertex* quad = &va[i];
quad[0].position = sf::Vector2f(t.get_x() - m_game.get_camera().x, t.get_y() - m_game.get_camera().y);
quad[1].position = sf::Vector2f(t.get_x() + 16 - m_game.get_camera().x, t.get_y() - m_game.get_camera().y);
quad[2].position = sf::Vector2f(t.get_x() + 16 - m_game.get_camera().x, t.get_y() + 16 - m_game.get_camera().y);
quad[3].position = sf::Vector2f(t.get_x() - m_game.get_camera().x, t.get_y() + 16 - m_game.get_camera().y);
quad[0].texCoords = sf::Vector2f(x, y);
quad[1].texCoords = sf::Vector2f(x + 16, y);
quad[2].texCoords = sf::Vector2f(x + 16, y + 16);
quad[3].texCoords = sf::Vector2f(x, y + 16);
i++;
}
}
m_window.draw(va, &sprite_sheet);
But when I run it the position is weird, see screenshot. Why is this happening?