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

Author Topic: [SOLVED] Can't overlap different layers.  (Read 1718 times)

0 Members and 1 Guest are viewing this topic.

Whisperdraw

  • Newbie
  • *
  • Posts: 2
    • View Profile
[SOLVED] Can't overlap different layers.
« on: June 15, 2013, 06:10:03 pm »
Hello,
I'm quite new to SFML and this forum as well, so please excuse me if my conduct is abnormal.

I have a question about the draw method, the one from the Drawable base class.

The thing is, I have a class named MapStrip(drawable, transformable), of which several Tilemaps(like the ones on the tutorial) are private members. They represent different layers. I wrote the logic of the draw method as so:

void MapStrip::draw(sf::RenderTarget& target, sf::RenderStates states) const
    {
                //draw each layer
                target.draw(WallStrip, states);
                target.draw(FloorStrip, states);
                target.draw(ObjectLayer1, states);
                target.draw(ObjectLayer2, states);

    }

Since they are allways drawn in that order, I find no apparent algorythmic flaw... Unless of course, the draw method is not what I think it is.

The problem is: I'm only able to see the last thing I tell it to draw. In this case, the ObjectLayer2. If the line target.draw(WallStrip, states); came after it, then I would only see the WallStrip being displayed.

Does the draw method literally draw on the go? Or does it simply assing an "object" to the target and it's drawn after that, out of my control? I'm asking because I placed several breakpoints along this method and noticed nothing is drawn until it is exited.

If so, how can something like this be solved?

Thank you very much.
I will include below the code for the draw method on the Tilemap class:

void Tilemap::draw(sf::RenderTarget& target, sf::RenderStates states) const
    {
        // apply the transform
        states.transform *= getTransform();

        // apply the tileset texture
        states.texture = &Tileset;

        // draw the vertex array
        target.draw(Vertices, states);
    }
« Last Edit: June 15, 2013, 06:23:28 pm by Whisperdraw »

The Hatchet

  • Full Member
  • ***
  • Posts: 135
    • View Profile
    • Email
Re: Can't overlap different layers.
« Reply #1 on: June 15, 2013, 06:24:31 pm »
Well, nothing gets shown on the screen until you call the display() method on you window (which you are probably doing after you draw everything, which is how you should do it).  This is why at your breakpoints nothing shows up till after all the draw() methods.

As for why you only see the last thing drawn, if the last thing drawn covers the entire area of everything drawn before it of course that will be the only thing you see.  We have no idea how big, what shape, what kind of transparancy any of the objects you are drawing are unless you give us some more info, maybe slap some screens up on imgur something.

Whisperdraw

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: [SOLVED] Can't overlap different layers.
« Reply #2 on: June 15, 2013, 06:26:33 pm »
Well that was a quick solver.
Aparently the program I was using to draw the texures refuses to save the transparency...

Only when I changed the background to black did I notice there was something fishy going on because I saw the whole strip as it should be, and not only the last layer overlapping and completely hiding the others with it's fake white background transparency.

Oh well, may it serve as a lesson to other air-heads out there...

Thanks, The Hatchet, but it's solved already :)