I recently switched to using a vertex array for displaying the tiles, but sometimes I get lines between them, as you can see in the first attachment. And when I move it goes back to normal, as you can see in the second attachment. Does anyone know why this happens?
Code:
sf::VertexArray va(sf::Quads, m_game.get_loaded_chunks().size() * 2048);
int y = 0;
int x = 0;
sf::Texture sprite_sheet;
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 = (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() + 32 - m_game.get_camera().x, t.get_y() - m_game.get_camera().y);
quad[2].position = sf::Vector2f(t.get_x() + 32 - m_game.get_camera().x, t.get_y() + 32 - m_game.get_camera().y);
quad[3].position = sf::Vector2f(t.get_x() - m_game.get_camera().x, t.get_y() + 32 - 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);
if(t.get_attribute() != 0){
sf::Vertex* att = &va[i + 4];
att[0].position = sf::Vector2f(t.get_x() - m_game.get_camera().x, t.get_y() - m_game.get_camera().y);
att[1].position = sf::Vector2f(t.get_x() + 32 - m_game.get_camera().x, t.get_y() - m_game.get_camera().y);
att[2].position = sf::Vector2f(t.get_x() + 32 - m_game.get_camera().x, t.get_y() + 32 - m_game.get_camera().y);
att[3].position = sf::Vector2f(t.get_x() - m_game.get_camera().x, t.get_y() + 32 - m_game.get_camera().y);
if(t.get_attribute() == 1){
att[0].texCoords = sf::Vector2f(221, 153);
att[1].texCoords = sf::Vector2f(221 + 16, 153);
att[2].texCoords = sf::Vector2f(221 + 16, 153 + 16);
att[3].texCoords = sf::Vector2f(221, 153 + 16);
}
else if(t.get_attribute() == 2){
att[0].texCoords = sf::Vector2f(459, 187);
att[1].texCoords = sf::Vector2f(459 + 16, 187);
att[2].texCoords = sf::Vector2f(459 + 16, 187 + 16);
att[3].texCoords = sf::Vector2f(459, 187 + 16);
}
else if(t.get_attribute() == 3){
att[0].texCoords = sf::Vector2f(443, 170);
att[1].texCoords = sf::Vector2f(443 + 16, 170);
att[2].texCoords = sf::Vector2f(443 + 16, 170 + 16);
att[3].texCoords = sf::Vector2f(443, 170 + 16);
}
}
i += 8;
}
}
m_window.draw(va, &sprite_sheet);