Welcome,
Guest
. Please
login
or
register
. Did you miss your
activation email?
French forum
Home
Help
Search
Login
Register
SFML community forums
»
Help
»
Graphics
»
Question about textures and shapes
Print
Pages: [
1
]
Author
Topic: Question about textures and shapes (Read 3536 times)
0 Members and 1 Guest are viewing this topic.
MaeZer
Newbie
Posts: 9
Question about textures and shapes
«
on:
May 27, 2015, 09:56:34 pm »
I would like to set the texture of a RectangleShape, but I don't understand how you do it like in the documentation. Can someone tell me how to do it please? I created my texture and rectangleshape but I don't know how you actually set it. My code doesn't seem to work.
sf
::
Texture
rectex
;
rectex.
loadFromFile
(
"resources/texture"
)
;
rectangle.
setTexture
(
rectex
)
;
Logged
Hapax
Hero Member
Posts: 3379
My number of posts is shown in hexadecimal.
Re: Question about textures and shapes
«
Reply #1 on:
May 27, 2015, 09:59:22 pm »
What doesn't work? What goes wrong?
You should be aware that the texture you're loading here is missing a file extension.
Logged
Selba Ward
-SFML drawables
Cheese Map
-Drawable Layered Tile Map
Kairos
-Timing Library
Grambol
*
Hapaxia Links
*
MaeZer
Newbie
Posts: 9
Re: Question about textures and shapes
«
Reply #2 on:
May 27, 2015, 10:03:47 pm »
Oops I forgot the extension
Corrected it
It says after .setTexture "No suitable conversion function from sf::Texture to const sf::Texture* exists"
Logged
Hapax
Hero Member
Posts: 3379
My number of posts is shown in hexadecimal.
Re: Question about textures and shapes
«
Reply #3 on:
May 27, 2015, 10:16:09 pm »
Ah, unlike
sf::Sprite
's
setTexture()
which takes a
reference
to an sf::Texture,
sf::RectangleShape
's
setTexture()
takes a
pointer
to an sf::Texture.
Try:
rectangle.
setTexture
(
&
rextex
)
;
Does that fix your problem?
It's actually sf::Shape that takes the pointer and sf::RectangleShape is derived from that.
Not sure why Shape takes a pointer while Sprite takes a reference. For consistency, they should be the same (preferably reference) if possible.
«
Last Edit: May 27, 2015, 10:20:24 pm by Hapax
»
Logged
Selba Ward
-SFML drawables
Cheese Map
-Drawable Layered Tile Map
Kairos
-Timing Library
Grambol
*
Hapaxia Links
*
MaeZer
Newbie
Posts: 9
Re: Question about textures and shapes
«
Reply #4 on:
May 27, 2015, 10:19:59 pm »
Aha, it works perfectly now thanks
Logged
Hapax
Hero Member
Posts: 3379
My number of posts is shown in hexadecimal.
Re: Question about textures and shapes
«
Reply #5 on:
May 27, 2015, 10:20:38 pm »
You're welcome
Logged
Selba Ward
-SFML drawables
Cheese Map
-Drawable Layered Tile Map
Kairos
-Timing Library
Grambol
*
Hapaxia Links
*
shadowmouse
Sr. Member
Posts: 302
Re: Question about textures and shapes
«
Reply #6 on:
May 27, 2015, 10:26:47 pm »
Is there any reason why they take it differently, even though the function is used in the same way by the user?
Logged
eXpl0it3r
SFML Team
Hero Member
Posts: 11034
Re: Question about textures and shapes
«
Reply #7 on:
May 27, 2015, 10:31:51 pm »
Because shapes don't have to have a texture, thus one needs to be able to set it to NULL, while sprites always need a texture.
Logged
Official FAQ:
https://www.sfml-dev.org/faq.php
Official Discord Server:
https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog:
https://duerrenberger.dev/blog/
Hapax
Hero Member
Posts: 3379
My number of posts is shown in hexadecimal.
Re: Question about textures and shapes
«
Reply #8 on:
May 27, 2015, 10:46:56 pm »
That makes sense. It's just confusing that they work differently.
Logged
Selba Ward
-SFML drawables
Cheese Map
-Drawable Layered Tile Map
Kairos
-Timing Library
Grambol
*
Hapaxia Links
*
Print
Pages: [
1
]
SFML community forums
»
Help
»
Graphics
»
Question about textures and shapes