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

Author Topic: (SOLVED) sf::Sprite.getTexture() Help?  (Read 6712 times)

0 Members and 1 Guest are viewing this topic.

TheGoldenFyre

  • Newbie
  • *
  • Posts: 18
    • View Profile
(SOLVED) sf::Sprite.getTexture() Help?
« 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!
« Last Edit: January 02, 2016, 01:53:00 pm by TheGoldenFyre »

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

TheGoldenFyre

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: sf::Sprite.getTexture() Help?
« Reply #2 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.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: sf::Sprite.getTexture() Help?
« Reply #3 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() 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.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

TheGoldenFyre

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: sf::Sprite.getTexture() Help?
« Reply #4 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.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: sf::Sprite.getTexture() Help?
« Reply #5 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() returns a pointer to a texture, not a texture itself (not that you can compare two texture objects anyway).
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: sf::Sprite.getTexture() Help?
« Reply #6 on: January 02, 2016, 01:29:52 pm »
Even though I answered your question (twice), I'm feeling generous.

(click to show/hide)
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

TheGoldenFyre

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: sf::Sprite.getTexture() Help?
« Reply #7 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.