Skip to content
Marc Flerackers edited this page Jun 9, 2024 · 8 revisions

Layers are coming back soon in Kaplay. Though there are a few things which need to be discussed. Layers works as follows:

layers(["bg", "game", "ui"], "game");

// bg layer
add([
    rect(width(), height()),
    layer("bg"),
    color(rgb(64, 128, 255))
])

Currently it only works locally, like z does. The plan is to change it to work globally. This means all visible nodes are collected in tree order, then sorted on layer and z.

There are a few known caveats:

  • The mask component works on the children of the node it is attached to. With local sorting there is no problem. With global sorting, the children may be in another layer and not drawn right after the mask is set. So the children need to know that they need to set the mask first, before drawing. This adds quite some complexity. Unity has mask as a component, but on the object which is masked.
  • The drawon component is similar. It switches the current framebuffer for its owner and children.

Clone this wiki locally