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

Author Topic: Drawing different views with the same tileset.  (Read 1028 times)

0 Members and 1 Guest are viewing this topic.

walru

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Drawing different views with the same tileset.
« on: May 26, 2023, 02:50:24 pm »
Hello,

I have a class with essentially the following drawable function:
Code: [Select]
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const{
    states.transform*=getTransform();
    states.texture=&m_tileset;
    target.draw(m_vertices, states);
}

I want to be able to change the "m_vertices" between two different views where the tiles shown in one view remain unchanged after each draw but the other the tile placements can change. As far as I can tell, I can't change the draw function to have an option to select different "m_vertices" at draw time. I think that I could run set two instances of the class for each view but then I would have to load the tileset twice when initializing or set a separate function that sets a flag that changes the "m_vertices" before the tiles are drawn. Are these the only options or is there another way to adjust the drawable for the class?


Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Drawing different views with the same tileset.
« Reply #1 on: May 27, 2023, 04:05:54 pm »
The most obvious solution would be separate the stuff that gets drawn to different views. The stuff that "stays the same in multiple views" could have its own view and drawn separately.

Other options include:
- saving two copies of m_vertices - each with different versions for each view - and drawing the correct one depending on 'some flag'.
- setting m_vertices to "mutable". this could be considered a bad design since there are other, safer, options. Mutable allows you to change it inside a const function, such as sf::Drawable's draw(). Still, you'd need to a) know when it needs changing so 'some flag' would still be needed, and b) update the vertices every single time it is drawn, which might not be necessary using other methods (in fact, if you're already updating them before the draw, you're updating twice!)
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything