level(map: string[], opt?: LevelOpt): LevelComp

Construct a level based on symbols.

parammap- The map data.

paramopt- The level options.

paramunknown- The parent object of the level. Defaults to root.

const myLevel = add([
    level([
         "                          $",
         "                          $",
         "           $$         =   $",
         "  %      ====         =   $",
         "                      =    ",
         "       ^^      = >    =   &",
         "===========================",
    ], {
        // define the size of tile block
        tileWidth: 32,
        tileHeight: 32,
        // define what each symbol means, by a function returning a component list (what will be passed to add())
        tiles: {
            "=": () => [
                sprite("floor"),
                area(),
                body({ isStatic: true }),
            ],
            "$": () => [
                sprite("coin"),
                area(),
                pos(0, -9),
            ],
            "^": () => [
                sprite("spike"),
                area(),
                "danger",
            ],
        }
    })
])

returnsA game obj with the level.

sincev4000.0

groupComponents

kaplay logo

Misc

Layer