#1526·melonJS

[Feature request] Add support for Y-based Z sorting in batch rendering

Author: VarenielCreated Jun 30, 2026Updated Jun 30, 2026
LabelsFeature

Is your feature request related to a problem? Please describe.

Yes. I need a Y-based Z sorting feature for sprites, especially when using batch rendering.

Currently, I use custom auto-sorting logic that updates each object’s pos.z based on pos.y and _anchorZ property. This works for normal rendering, but batch rendering can cause incorrect render order, disappearing sprites, or a sprite using another sprite’s texture.

Describe the solution you'd like

I would like batch rendering to support Y-based Z sorting properly.

Objects should be sorted using their calculated pos.z, for example:

nextZ = baseZ + object.pos.y + scaledAnchorZ;

This allows objects lower on the screen to render in front of objects higher on the screen.

Example:

Object A: pos.y = 100 Object B: pos.y = 150

Expected result: Object B should render above Object A because it has a higher pos.y value.

Describe alternatives you've considered

I currently use a custom auto-sort system that updates pos.z manually and calls container.sort(). However, this does not fully work with batch rendering.

I also tried disabling auto sorting, but that caused other rendering issues, such as sprites disappearing after one mob is destroyed.

Additional context