Skip to content

Commit 06151fd

Browse files
committed
Sorted entities before drawing so they overlap correctly
1 parent c081876 commit 06151fd

File tree

3 files changed

+5
-0
lines changed

3 files changed

+5
-0
lines changed

main.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,11 @@ int main()
286286
//---- Draw items ----
287287
// Draw tilemap with walls and healthPickups
288288
renderer.draw(window, map);
289+
// Sort by Y position before drawing, so that the highest objects are drawn first
290+
std::sort(entities.begin(), entities.end(),
291+
[](const std::shared_ptr<Entity>& a, const std::shared_ptr<Entity>& b) {
292+
return a->getPosition().y < b->getPosition().y;
293+
});
289294
// Draw all shadows for entities (enemies and player)
290295
for (auto& e : entities) { e->drawShadow(window); }
291296
// Draw and update all entity sprites

main.exe

3.5 KB
Binary file not shown.

main.obj

12.9 KB
Binary file not shown.

0 commit comments

Comments
 (0)