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

Author Topic: question for setTexture (const Texture *texture, bool resetRect=false)  (Read 2456 times)

0 Members and 1 Guest are viewing this topic.

LifelongStudent

  • Newbie
  • *
  • Posts: 2
    • View Profile
Hey guys, I hope you are doing well.

This is a conceptual question not a "why doesn't this work" question.

I was reading the documentation for SFML 2.0  and I could not help but take note of the function signature for setTexture that is different than other functions in the graphics library.

Namely the fact that this function takes a const pointer to a sf::texture object, while almost all other functions in the library use const references instead of const pointers (setOutlineColor, setPosition, setFillColor to name a few)

needless to say, a pass by const reference and const pointer are very similar semantically but I am suspicious that there must be a very good reason for this choice to grant such inconsistency in style.

Have a good day


Arcade

  • Full Member
  • ***
  • Posts: 230
    • View Profile
Re: question for setTexture (const Texture *texture, bool resetRect=false)
« Reply #1 on: December 03, 2015, 09:48:20 pm »
Taking in a const pointer allows the user to set the texture to NULL, which will disable texturing. This makes sense where you want that option, such as with sf::RectangleShape for example. You may want to just set a color instead of a texture.

You may notice that setTexture does take in a reference for sf::Sprite because it doesn't make sense to allow disabling the texture in that case.

LifelongStudent

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: question for setTexture (const Texture *texture, bool resetRect=false)
« Reply #2 on: December 03, 2015, 10:16:48 pm »
That is a very logical answer, Thanks

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: question for setTexture (const Texture *texture, bool resetRect=false)
« Reply #3 on: December 03, 2015, 10:40:40 pm »
You're not the first one to ask this question. However it can easily be answered by simply reading the corresponding documentation and tutorial...

Quote from: documentation
texture can be NULL to disable texturing
Quote from: tutorial
To disable texturing, call setTexture(NULL).
Laurent Gomila - SFML developer

 

anything