SFML community forums

Help => General => Topic started by: NeonFireYT on January 20, 2021, 01:13:56 am

Title: Drawing Too Many Sprites Slows Down Game
Post by: NeonFireYT on January 20, 2021, 01:13:56 am
Hi all, I'm relatively new to SFML and decided to make a simple game where you control a platform and you capture falling fruits. To draw the fruits, I simply store the Fruit pointers in a Vector2f and draw the sprites associated with each pointer. Furthermore, I move each sprite a few pixels every loop so that it may "fall" down the screen. unfortunately, I noticed that the more sprites I draw, i.e. the larger the vector, the slower my game gets. It lags terrible when I double the amount of fruits and moving the platform is unbearably slow, even though normally it would move fine. I will include the relative parts of the code here. Any help would be greatly appreciated. This is my first game meant to be a test, and see what I could possibly do in the future.
Title: Re: Drawing Too Many Sprites Slows Down Game
Post by: Stauricus on January 20, 2021, 02:32:55 am
when posting code, put it in the post (with [ code ] tags), not as separated source files.
are you letting the cpu sleep between frames? there is a specific function for that, sf::sleep:
https://www.sfml-dev.org/documentation/2.5.1/group__system.php#gab8c0d1f966b4e5110fd370b662d8c11b
Title: Re: Drawing Too Many Sprites Slows Down Game
Post by: kojack on January 31, 2021, 03:25:50 pm
I don't see anything in there that would cause excessive slowness. It's just 144 sprites in the code (is that a number that is lagging, or is that the acceptable value?).

One thing to check, are you doing a debug or release build? Debug builds can be hundreds of times slower (due to all the extra safety checks and because optimisation is disabled).