Hello, ı was looking for a way to draw tile in game dynamically(edit or change at run time). I though of is i use vertexarray it can be done. Well it does the job excellently but fps drops very quick.
Commended vertex code (release ) = 2000+-
UnCommended vertex code (release) = 21+-1
There is massive difference in fps
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 800), "SFML works!");
sf::CircleShape shape(100.f);
shape.setFillColor(sf::Color::Green);
sf::VertexArray quad(sf::Quads, 4);
while (window.isOpen())
{
window.clear();
sf::Event event;
int size{ 20 };
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
for (int x = 0; x < 40; x++)
{
for (int y = 0; y < 40; y++)
{
quad[0].position = sf::Vector2f(x, y);
quad[1].position = sf::Vector2f(x*size, y);
quad[2].position = sf::Vector2f(x*size, y*size);
quad[3].position = sf::Vector2f(x, y*size);
window.draw(quad);
}
}
window.display();
}
return 0;
}
The code is pretty much the one from tutorial with the vertex just added. I know the for loops in combine call 40*40 time but i didnt expect it to fall this quick. Is there a alternative way to do it ?