SFML community forums

Help => Graphics => Topic started by: Drak on May 17, 2011, 08:40:25 am

Title: Sprites not Overlapping
Post by: Drak 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).
Title: Sprites not Overlapping
Post by: PhiLLe 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.
Title: Sprites not Overlapping
Post by: slotdev 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 :)