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

Author Topic: Is it expensive to create Sprite object each frame instead of storing it?  (Read 1862 times)

0 Members and 1 Guest are viewing this topic.

Satus

  • Guest
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?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10801
    • View Profile
    • development blog
    • Email
Re: Is it expensive to create Sprite object each frame instead of storing it?
« Reply #1 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.
« Last Edit: February 13, 2017, 08:28:21 pm by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Satus

  • Guest
Re: Is it expensive to create Sprite object each frame instead of storing it?
« Reply #2 on: February 13, 2017, 07:50:50 pm »
Thanks for the answer!  :)

 

anything