layer is not defined in kaboomjs v3000

50 Views Asked by At

I'm following this tutorial that uses the layer() function in the latest version of kaboom (v3000)

But I got this message where the layer function is not defined

ReferenceError: layer is not defined

Did they remove it ? or did they rename to something else ?

1

There are 1 best solutions below

0
dytra On

According to this github issue

layers() has been removed and the functionality of layers can be converged into parent game objects, making it an redundant system.

Old:

kaboom()

loadSprite("bean", "/sprites/bean.png")

// layer "ui" will be on top of layer "game", with "game" layer being the default
layers([
    "game",
    "ui",
], "game")

add([
    sprite("bean"),
    scale(5),
    // specify layer with layer() component
    layer("ui"),
    color(0, 0, 255),
])

// this obj doesn't have a layer() component, fallback on default "game" layer
add([
    sprite("bean"),
    pos(100, 100),
    scale(5),
])

New

kaboom()

loadSprite("bean", "/sprites/bean.png")

// Create a parent node that won't be affected by camera (fixed) and will be drawn on top (z of 100)
const ui = add([
    fixed(),
    z(100),
])

// This will be on top, because the parent node has z(100)
ui.add([
    sprite("bean"),
    scale(5),
    color(0, 0, 255),
])

add([
    sprite("bean"),
    pos(100, 100),
    scale(5),
])