SFML community forums

Help => General => Topic started by: Satus on February 13, 2017, 03:22:35 pm

Title: Is it expensive to create Sprite object each frame instead of storing it?
Post by: Satus on February 13, 2017, 03:22:35 pm
Hi. Just a quick question: would  there be any noticeable performance difference between storing sf::Sprite object  as a field and creating new object each frame?
Title: Re: Is it expensive to create Sprite object each frame instead of storing it?
Post by: eXpl0it3r on February 13, 2017, 04:01:12 pm
Sprite is a light object, so there won't be a performance impact.
But don't just do it out of laziness. Think about the design and consider in which situation it makes sense to store the sprite and in which it doesn't. Ideally you'll want to have some sort of entity class at one point anyways that you'll have to store somewhere, which then can derive from sf::Drawable and hold an sf::Sprite for example.
Title: Re: Is it expensive to create Sprite object each frame instead of storing it?
Post by: Satus on February 13, 2017, 07:50:50 pm
Thanks for the answer!  :)