layer(name: string): LayerComp

Determines the layer for objects. Object will be drawn on top if the layer index is higher.

paramname- The layer name to set.

// Define layers
layers(["background", "game", "foreground"], "game")

const bean = add([
    sprite("bean"),
    pos(100, 100),
    layer("background"),
])

// Mark is in a higher layer, so he will be drawn on top of bean
const mark = add([
    sprite("mark"),
    pos(100, 100),
    layer("game"),
])

bean.layer("foreground") // Bean is now in the foreground layer and will be drawn on top of mark

returnsThe layer comp.

sincev3001.0

kaplay logo

Misc

Layer