Howdy, I am new to SFML and C++ to some degree as well.
My issue is that when I display my character sprite and a large background sprite I get a massive drop in frame rate. My window is only 512 x 448 and I am aiming for 60fps, but only getting 18-19 with a monolithic background sprite. I imagine that this will only get worse as I add bad dudes and such. I tried toying around with leaving the background sprite out of the loop and adding a function to redraw the background directly over just where the character was and removing the clear.window, but there seems like a much easier way should be out there but after a lot of googling I wasn't able to find it or not skillful enough to recognize/implement it.
Any help would be much appreciated
int main() {
setup();
sf::RenderWindow window(sf::VideoMode(512, 448), "Zelda");
window.setFramerateLimit(60);
sf::Clock clock;
while (window.isOpen()) {
sf::Event event;
while (window.pollEvent(event)) {
switch (event.type) {
case sf::Event::Closed:
window.close();
break;
}
}
window.clear();
input();
environmentcontrol(); //supplies sprite name, coords on spritesheet etc
///////Environment//////
if (spriteenv != "null") {
sf::Texture texture;
if (!texture.loadFromFile(spriteenv)) {
cout << "Didnt Load Sprite" << endl;
}
sf::Sprite sprite(texture);
sprite.setPosition(envx, envy);
sprite.setTextureRect(sf::IntRect(envx1, envy1, envx2, envy2));
window.draw(sprite);
}
spritecontrol(); //supplies character sprite file name, sheet location and window position
////////SPRITE 1////////
if (sprite1 != "null") {
sf::Texture texture;
if (!texture.loadFromFile(sprite1)) {
cout << "Didnt Load Sprite" << endl;
}
sf::Sprite sprite(texture);
sprite.setPosition(sp1x, sp1y);
sprite.setTextureRect(sf::IntRect(sp1x1, sp1y1, sp1x2, sp1y2));
sprite.setColor(sf::Color(255, 255, 255, 255));
window.draw(sprite);
}
sf::Time time = clock.getElapsedTime();
cout << 1.0 / time.asSeconds() << endl;
clock.restart().asSeconds();
window.display();
}
}