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

Author Topic: Why doesn't this work?  (Read 1986 times)

0 Members and 1 Guest are viewing this topic.

mbuckley2000

  • Newbie
  • *
  • Posts: 7
    • View Profile
Why doesn't this work?
« on: December 16, 2013, 07:45:38 pm »
Hey,

I am trying to set one sprites texture to be the same as another's, but it wont compile..

Like this:
Sprite.setTexture(Sprite2.getTexture);

I also tried:
Like this:
Sprite.setTexture(Sprite2.getTexture());


Any help would be greatly appreciated :)

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Why doesn't this work?
« Reply #1 on: December 16, 2013, 07:51:50 pm »
The types don't match (pointer vs reference). I'm sure the compiler message would tell that, but you have to actually read it.

And please have at least a look at the documentation before asking such questions...
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

mbuckley2000

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Why doesn't this work?
« Reply #2 on: December 16, 2013, 08:17:04 pm »
I did read it.. I suppose what I should have asked is how can I perform this action without creating more images?

The Terminator

  • Full Member
  • ***
  • Posts: 224
  • Windows and Mac C++ Developer
    • View Profile
Re: Why doesn't this work?
« Reply #3 on: December 16, 2013, 08:39:56 pm »
I did read it.. I suppose what I should have asked is how can I perform this action without creating more images?

If you read it, then you'd ought to familiarize yourself with pointers and references. Plus, judging that you tried to call a function without parentheses makes it quite obvious you don't know the basics of C++. I'd recommend getting a good C++ book. To answer your question, sf::Sprite::setTexture takes a reference to a const Texture, and sf::Sprite::getTexture returns a pointer to a const Texture. For your second try, you're passing a pointer as an argument instead of a reference.
Current Projects:
Technoport

mbuckley2000

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Why doesn't this work?
« Reply #4 on: December 16, 2013, 10:14:04 pm »
OK, thanks for the advice.. I was planning to try and learn on the job as I have coded games previously in other languages but I will take your advice and learn more of the theory first :)

wintertime

  • Sr. Member
  • ****
  • Posts: 255
    • View Profile
Re: Why doesn't this work?
« Reply #5 on: December 17, 2013, 09:00:55 am »
You should have kept the Texture around anyways to prevent the white box problem, so you should not need to ask the Sprite for it and be able to directly use it for the other Sprite.
http://sfml-dev.org/tutorials/2.1/graphics-sprite.php