# Depth Sorting in h2d.Layers with Added Sprite (heaps)

**URL:** <https://community.haxe.org/t/depth-sorting-in-h2d-layers-with-added-sprite-heaps/751>\
**Category:** Haxe\
**Created:** [June 5, 2018, 7:32pm UTC](https://community.haxe.org/t/depth-sorting-in-h2d-layers-with-added-sprite-heaps/751 "2018-06-05T19:32:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pinkboi](https://community.haxe.org/user_avatar/community.haxe.org/pinkboi/32/2416_2.png) [@pinkboi](https://community.haxe.org/u/pinkboi)\
**Post date:** [June 5, 2018, 7:32pm UTC](https://community.haxe.org/t/depth-sorting-in-h2d-layers-with-added-sprite-heaps/751/1 "2018-06-05T19:32:45Z")

</div>

I’m using `h2d.CdbLevel` (derived from `h2d.Level`) to load a map made in castledb and that works. I can also confirm loading a map I made with tall objects that depth sorting works right for the objects layer. However, I’m not sure how to add a sprite into it that gets properly depth-sorted. I see a `ysort` function on `Layers` and I see it getting called in the sync method on `CdbLevel`. I tried adding it as a separate layer and I’ve tried adding it as a child to the different layers. Do I need to setup my own depth-sorting that accommodates added sprites? You can see the code in its current state here:

> **[Haxe Nixie / nixie](https://gitlab.com/haxe-nixie/nixie)**
>
> 2D RPG and Visual Novel engine using haxe, heaps and castledb

---

<div class="post-metadata">

**Author:** ![pinkboi](https://community.haxe.org/user_avatar/community.haxe.org/pinkboi/32/2416_2.png) [@pinkboi](https://community.haxe.org/u/pinkboi)\
**Post date:** [June 7, 2018, 12:21am UTC](https://community.haxe.org/t/depth-sorting-in-h2d-layers-with-added-sprite-heaps/751/2 "2018-06-07T00:21:28Z")

</div>

Setting the layer with trees and rocks to objects mode instead of tile mode fixed the issue (it’s set to tile mode in the aforementioned sample). Along with setting the dx, dy to the the bottom center of the tile I base the sprite on. These changes are reflected in the repo I linked to (nixie).
