SFML community forums
Help => Graphics => Topic started by: JasonLeon on March 10, 2025, 04:05:58 pm
-
The particle class is inherited from Sprite.
It's terribly laggy when there's over 10,000 particles moving at the same time.
It's very slow when changing those vertexes' position in function Update().
Is there any solution? Thanks for your time.
-
Or I should just use Sprite lists and draw them particle by particle?
-
The best option is pretty much always to draw them all together as a single vertex array (https://www.sfml-dev.org/tutorials/3.0/graphics/vertex-array/). However, it's (a little bit) more complicated than just drawing lots of sprites.
Another option is to use some form of sprite batching. You can use a pre-made one or make your own.
I have two types already created:
https://github.com/SFML/SFML/wiki/Source%3A-Simple-Sprite-Batcher
takes a vector of pointers to already-created sprites and batches them into a single vertex array. This can be done every frame if required and should see an increase of speed to around 200% (or more!).
Here's a video example (warning: fast movement - flickering effects - may be unsuitable to watch):
https://www.youtube.com/watch?v=2P13hhMgeFs
https://github.com/Hapaxia/SelbaWard/wiki/Sprite-Batch
is a different approach. It itself contains the sprites and you update them via its interface (or copy a sf::Sprite). This way it can make internal optimisations so should result in better/faster results. This is a part of Selba Ward (https://github.com/Hapaxia/SelbaWard/wiki) so feel free to have a look around for other things there you'd like to use too ;)