In the 2D context, Z-Index, or depth, only exists in the context of the Layers object.
public static function setZIndex(obj: h2d.Object, idx: Int, ?parentLayer: Layers): Layers {
if(parentLayer == null){
parentLayer = new Layers(obj.parent);
obj.parent.addChild(parentLayer);
}
parentLayer.add(obj, idx);
return parentLayer;
}
Scenes are layers, so you can just use those.
setZIndex(obj, 100, state.scene);
The Heaps API for z-index manipulation is unintuitive and would benefit from a dedicated depth field on objects.
From the user side, a more complex management object might be required for comprehensive manipulation.