The problem is that it's hard to intermingle rendering of nodes in Cocos2dx. We actually use our own batching mechanism (similar to Unity) to draw skeletons more effectively, however, intermingling rendering of parts of nodes isn't as straight forward.
Your initial approach (making some slots invisible) was actually quite spot on, however, you'll have to modify SkeletonRenderer
a little.
The method to fix up is SkeletonRenderer::render
. There, we walk through the slots, in the current draw order, and assemble the mesh(es) needed for drawing spine-runtimes/SkeletonRenderer.cpp at 3.6
You could add a method on SkeletonRenderer
that lets you set the slot indices or names of the start and end slots, you want to draw. In the render method, you then iterate through the slots. Until the start slot is iterated over, you simply skip all slots up until that point. Once the start slot is iterated over, you let the normal rendering logic in that loop execute. Once you hit the end slot, you can break out of that loop.
With this, you can selectively draw a range of slots at runtime depending on your needs. You can then use 2 SkeletonRenderer nodes, one for the front slots and one for the back slots, and squish any other node you want between those two in your scene graph.
I've created an issue here [cocos2d] add SkeletonRenderer::setSlotRange(startSlot, endSlot) to render only slots in that range Β· #1075, if I find some time I'll try to get this implemented this week.