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

Author Topic: [SOLVED] - sf::Sprite is not a drawable?  (Read 3158 times)

0 Members and 1 Guest are viewing this topic.

BiiXteR

  • Newbie
  • *
  • Posts: 20
    • View Profile
[SOLVED] - sf::Sprite is not a drawable?
« on: January 11, 2016, 06:58:54 pm »
So, currently I have this :


std::map<std::string, sf::Sprite*> sprites;


and I loop trough it like this :
        for (auto const& i : sprites)
        {
                window->draw(i.second);
        }
 
But when I try to run it, it tells me that :

illegal indirection
 void sf::RenderTarget::draw(const sf::Vertex *,size_t,sf::PrimitiveType,const sf::RenderStates &)': cannot convert argument 1 from 'sf::Sprite *const ' to 'const sf::Drawable &

Reason: cannot convert from 'sf::Sprite *const ' to 'const sf::Drawable'
No constructor could take the source type, or constructor overload resolution was ambiguous



Note :
I'm pretty new to both C++ and SFML so it might be obvious.
It might not even be a SFML problem.
 :P
« Last Edit: January 12, 2016, 07:21:37 am by BiiXteR »

G.

  • Hero Member
  • *****
  • Posts: 1592
    • View Profile
Re: sf::Sprite is not a drawable?
« Reply #1 on: January 11, 2016, 07:13:05 pm »
The draw function accepts sf::Sprite, but not pointers to sf::Sprite. And i.second is a pointer to an sf::Sprite.
You need to dereference your pointer.
window->draw(*i.second);

BiiXteR

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: sf::Sprite is not a drawable?
« Reply #2 on: January 11, 2016, 07:49:03 pm »
The draw function accepts sf::Sprite, but not pointers to sf::Sprite. And i.second is a pointer to an sf::Sprite.
You need to dereference your pointer.
window->draw(*i.second);

I could have sworn I already tried that... But anyways, it worked!  :)
Thank you!

Also, new to this forum, do you know how accepting/marking an answer works?

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: sf::Sprite is not a drawable?
« Reply #3 on: January 11, 2016, 07:54:41 pm »
Also, new to this forum, do you know how accepting/marking an answer works?

This forum doesn't have that option, but if you want you can put '[SOLVED]' in the title of the thread (edit the first post).
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor