SFML community forums

Help => Graphics => Topic started by: TheGoldenFyre on January 02, 2016, 10:05:39 am

Title: (SOLVED) sf::Sprite.getTexture() Help?
Post by: TheGoldenFyre on January 02, 2016, 10:05:39 am
Can someone show me how you would be able to do something like this?

Code: [Select]
if (Sprite[i].getTexture() == Texture) {
                      //code
}

I just can't get it to work.
Thank you for any help!
Title: Re: sf::Sprite.getTexture() Help?
Post by: Nexus on January 02, 2016, 12:23:08 pm
http://en.sfml-dev.org/forums/index.php?topic=5559
Title: Re: sf::Sprite.getTexture() Help?
Post by: TheGoldenFyre on January 02, 2016, 12:37:29 pm
AMD A6-6310 APU, Windows 10. SFML 2.3. Visual Studio 2015 community. Everything else works fine, i'm just wondering how .getTexture could be used in an if-statement, and searching for it doesn't help.
Title: Re: sf::Sprite.getTexture() Help?
Post by: Hapax on January 02, 2016, 01:12:13 pm
What doesn't work?

What are you attempting to do?
Comparing two textures to see if they contain the same data? You should be using sf::Image for this.
Comparing two textures to see if they are the same texture object? You can use pointers/addresses:
if (sprite.getTexture() == &texture)
sf::Sprite::getTexture() (http://www.sfml-dev.org/documentation/2.3.2/classsf_1_1Sprite.php#a2c4fbb983b29e14f9bb69a3a75feae46) returns a pointer to a texture, not a texture itself (not that you can compare two texture objects anyway).

The link that Nexus posted doesn't say "provide your computer details", it is a very important post that says that you should give enough information about the problem and what actually goes wrong/doesn't work.
Title: Re: sf::Sprite.getTexture() Help?
Post by: TheGoldenFyre on January 02, 2016, 01:15:08 pm
I'm trying to see if two textures are the same. The base texture (the texture itself) and the texture that is assigned to the sprite. I don't know how I would do this, mainly because I don't understand what the .getTexture returns and how to use it for a comparison.
Title: Re: sf::Sprite.getTexture() Help?
Post by: Hapax on January 02, 2016, 01:24:25 pm
I'm trying to see if two textures are the same. The base texture (the texture itself) and the texture that is assigned to the sprite.
Again, I ask: the same data in each texture or both pointing to the same object?

I don't know how I would do this, mainly because I don't understand what the .getTexture returns and how to use it for a comparison.
if (sprite.getTexture() == &texture)
sf::Sprite::getTexture() (http://www.sfml-dev.org/documentation/2.3.2/classsf_1_1Sprite.php#a2c4fbb983b29e14f9bb69a3a75feae46) returns a pointer to a texture, not a texture itself (not that you can compare two texture objects anyway).
Title: Re: sf::Sprite.getTexture() Help?
Post by: Hapax on January 02, 2016, 01:29:52 pm
Even though I answered your question (twice), I'm feeling generous.

(click to show/hide)
Title: Re: sf::Sprite.getTexture() Help?
Post by: TheGoldenFyre on January 02, 2016, 01:51:23 pm
I'm so f*cking stupid... Thanks a lot for the help anyways, even though i'm a stupid twat.
Even though I answered your question (twice), I'm feeling generous.

(click to show/hide)

I'm so stupid. Thanks anyways for the help, hope this works wel XD.