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

Author Topic: [SOLVED] sf::Drawable managment  (Read 1266 times)

0 Members and 1 Guest are viewing this topic.

DropboxKenshiro

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
[SOLVED] sf::Drawable managment
« on: July 08, 2018, 07:23:48 pm »
Hi there!

I'm doing SFML for a while, but I have a question. How to manage sf:Drawables in a game? I'll expand that:
I want to have something like that: I have a special object that stores all sf::Drawables in container, that object also has inherited draw(). All of this is to simply write one function to draw all the drawables. But i went to a problem well described here: https://en.sfml-dev.org/forums/index.php?topic=14262.0. So, I'm thinking, how to do that. I would have system that registers any drawables automatically, in object constructor. Somebody suggested using std::map and ID's, but it is possible to just use Vector?
« Last Edit: July 09, 2018, 01:22:17 pm by DropboxKenshiro »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: sf::Drawable managment
« Reply #1 on: July 08, 2018, 08:19:45 pm »
Maybe you could tell what the problem is again, because that other thread is long and we probably don't need to read it entirely ;)
Laurent Gomila - SFML developer

DropboxKenshiro

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: sf::Drawable managment
« Reply #2 on: July 09, 2018, 11:41:32 am »
Wow, Laurent here...

So, to summarize. My (and that guy's too) idea was to create std::vector of pointers to sf::Drawables. Idea was pretty nice, and everything was OK, until I went into deleting pointers. I created a typical loop using iterators, like this:
for(auto a = vector.begin(); a != vector.end();)
{
    if(**a == this->sprite)
    {
          //remove
     }
     else
     { ++i; }
}
 

The problem is, I cannot compare dereferenced iterator to our sprite. Visual Studio even gives weird error about sf::Sprite != sf::Sprite. And that's pretty much the case.

I thought about using some ID, but I don;t know if it is something good.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: sf::Drawable managment
« Reply #3 on: July 09, 2018, 12:43:03 pm »
If you store addresses in your vector, then compare addresses.

if (*a == &sprite)
{
    // remove
}
Laurent Gomila - SFML developer

DropboxKenshiro

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: sf::Drawable managment
« Reply #4 on: July 09, 2018, 12:56:09 pm »
I had same idea, but some strange errors happened. I will investigate the thing, and edit this post if I don't solve it.

Btw. thanks Laurent for small, but important help.

Edit: okay, I got problem Solved.
« Last Edit: July 09, 2018, 01:22:03 pm by DropboxKenshiro »