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

Author Topic: sprites  (Read 2764 times)

0 Members and 1 Guest are viewing this topic.

mihaineken

  • Newbie
  • *
  • Posts: 30
    • View Profile
    • Email
sprites
« 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.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
Re: sprites
« Reply #1 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. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

mihaineken

  • Newbie
  • *
  • Posts: 30
    • View Profile
    • Email
Re: sprites
« Reply #2 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.


eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
Re: sprites
« Reply #3 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... ;)
« Last Edit: April 27, 2013, 10:54:13 pm by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

mihaineken

  • Newbie
  • *
  • Posts: 30
    • View Profile
    • Email
Re: sprites
« Reply #4 on: April 27, 2013, 10:14:54 pm »
Yes, this must be it, thank you!

mihaineken

  • Newbie
  • *
  • Posts: 30
    • View Profile
    • Email
Re: sprites
« Reply #5 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

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: sprites
« Reply #6 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.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

mihaineken

  • Newbie
  • *
  • Posts: 30
    • View Profile
    • Email
Re: sprites
« Reply #7 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.