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

Author Topic: Is Sprite::setTexture() a heavy operation?  (Read 1717 times)

0 Members and 1 Guest are viewing this topic.

MickeyKnox

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Is Sprite::setTexture() a heavy operation?
« on: May 10, 2020, 12:29:13 am »
Should I implement some sort of check if my sprite already has the right texture set?
Or is there no overhead if I set the same texture again and again in the game loop?

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Is Sprite::setTexture() a heavy operation?
« Reply #1 on: May 10, 2020, 02:14:55 am »
It's not heavy/expensive in itself. It's really only changing a pointer to point elsewhere.

The part where it can affect performance is that switching textures can be an expensive part of drawing. So, drawing multiple objects with different textures will be (slightly) slower than drawing multiple objects with the same texture.

If, though, theoretically, you had only that one sprite, changing the sprite's texture thousands of times per frame wouldn't be a issue. Only at draw time, does it need to load up the texture.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything