SFML community forums

Help => Graphics => Topic started by: mihaineken on April 27, 2013, 07:56:43 pm

Title: sprites
Post by: mihaineken on April 27, 2013, 07:56:43 pm
So I have two sprites.

Window.draw(sprite1);
Window.draw(sprite2);

The problem is when I drag the first shape, over the second shape, the second shape overlaps the first shape.

I've tried to redraw the first shape when dragging but with no results.
I'm using SFML 2.
Title: Re: sprites
Post by: eXpl0it3r on April 27, 2013, 08:28:06 pm
I guess you didn't understand how the graphical ordering works in SFML. ;)

SFML draws everything in the order you call draw on them. For example
window.draw(sprite1);
window.draw(sprite2);
Draws always sprite1 first and then sprite2. If they overlap, sprite2, since it gets drawn last, will be drawn over sprite1.

window.draw(sprite2);
window.draw(sprite1);
Draws always sprite2 first and then sprite1. If they overlap, sprite1, since it gets drawn last, will be drawn over sprite2.

I hope that helped. ;)
Title: Re: sprites
Post by: mihaineken on April 27, 2013, 08:36:23 pm
Yes I understand, but I've tried to redraw the first shape when dragging and it still got overlapped.

Title: Re: sprites
Post by: eXpl0it3r on April 27, 2013, 10:01:09 pm
Yes I understand, but I've tried to redraw the first shape when dragging and it still got overlapped.
I'm not sure how you redraw it exactly, but the way SFML works is, that you always clear the whole screen, then draw stuff to it and then display it.
If you want it to overlap you should reorder the drawing order and not just redraw the shape... ;)
Title: Re: sprites
Post by: mihaineken on April 27, 2013, 10:14:54 pm
Yes, this must be it, thank you!
Title: Re: sprites
Post by: mihaineken on April 28, 2013, 08:31:05 am
I'm sorry, I just dont know how to do it.
I cant just clear the window ...

Do you have any solution for me ? thank you
Title: Re: sprites
Post by: zsbzsb on April 28, 2013, 02:33:54 pm
I cant just clear the window ...
You need to clear the window every frame. It is not optional, this is the way SFML works. The only solution to your problem is to clear the window every frame and redraw everything in the order you want it drawn.
Title: Re: sprites
Post by: mihaineken on April 30, 2013, 05:46:01 am
Well I find a solution to my problem that is so simple :
I've declared a pointer that is drawn last and every time I drag a shape, the pointer will contain the address of that shape.