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

Author Topic: Sprites not Overlapping  (Read 3224 times)

0 Members and 1 Guest are viewing this topic.

Drak

  • Newbie
  • *
  • Posts: 8
    • View Profile
Sprites not Overlapping
« on: May 17, 2011, 08:40:25 am »
When I render multiple sprites, when moving they go BEHIND other sprites on the screen.

I assume this is because of the render order. Is there anyway to make all sprites "overlap" other sprites? Entity's (just plain sf sprites) go "behind" static objects (just other sf sprites).

PhiLLe

  • Newbie
  • *
  • Posts: 36
    • View Profile
Sprites not Overlapping
« Reply #1 on: May 17, 2011, 02:04:37 pm »
Just draw the dynamic ones last. The last Sprite you draw will be the sprite displayed on top.

slotdev

  • Sr. Member
  • ****
  • Posts: 385
    • View Profile
Sprites not Overlapping
« Reply #2 on: May 18, 2011, 05:01:33 pm »
I just implemented a display list (ie. if it's in the list, it's on the screen), and a simple depthbuffer (Z buffer....but Z is the wrong thing to call it, really):

Code: [Select]

// This should be sortable with std::sort but I can't figure out how just yet..
// Make a copy of display list
std::vector<string>::const_iterator i;
std::map<string,SpriteObj*>::const_iterator sprItr;
std::vector<string> dispListCopy;
size_t dListPos = 0;
for (size_t i = 0; i < displayList.size(); i++)
{
dispListCopy.push_back(displayList[i]);
}
displayList.clear();
// Now re-order displayList based on Z buffer
for (int z = Z_BUFFER_MAX_DEPTH; z >= 0 ;  z--)
{
for (size_t i = 0; i < dispListCopy.size(); i++)
{
if (gameSprites[dispListCopy[i]]->GetZ() == z)
{
displayList.push_back(dispListCopy[i]);
}
}
}


Don't know if that helps but it works for me :)
SFML 2.1