SFML community forums
Help => Graphics => Topic started by: LifelongStudent on December 03, 2015, 09:41:47 pm
-
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
-
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.
-
That is a very logical answer, Thanks
-
You're not the first one to ask this question. However it can easily be answered by simply reading the corresponding documentation and tutorial...
texture can be NULL to disable texturing
To disable texturing, call setTexture(NULL).