Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Drawing Too Many Sprites Slows Down Game  (Read 1641 times)

0 Members and 1 Guest are viewing this topic.

NeonFireYT

  • Newbie
  • *
  • Posts: 1
    • View Profile
Drawing Too Many Sprites Slows Down Game
« 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.

Stauricus

  • Sr. Member
  • ****
  • Posts: 369
    • View Profile
    • A Mafia Graphic Novel
    • Email
Re: Drawing Too Many Sprites Slows Down Game
« Reply #1 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
Visit my game site (and hopefully help funding it? )
Website | IndieDB

kojack

  • Sr. Member
  • ****
  • Posts: 343
  • C++/C# game dev teacher.
    • View Profile
Re: Drawing Too Many Sprites Slows Down Game
« Reply #2 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).

 

anything