melonJS
    Preparing search index...

    Class LDtkWorld

    A world of an LDtk project, as the level director holds it: its levels, each where LDtk puts it. It is loaded by the project's name, level.load("world"), with every level or with the ones asked for; the others are added and removed while the game runs.

    Hierarchy

    • LDtkMap
      • LDtkWorld
    Index
    backgroundcolor: string

    the project's background color, as #rrggbb

    cols: number = 0

    its width in cells of the project's default grid

    container: Container | undefined

    the container it was added to, while it is loaded

    format: "ldtk"

    the format's name, as registered with the level director

    height: number = 0

    its height, in pixels

    the world: its layout, its levels and the area they cover

    layers: Renderable[] = []

    its tile layers, once it is loaded: TileLayer and PlacedTileLayer

    name: string

    the id it is loaded by: level.load(name)

    orientation: "orthogonal"

    the grid is square

    project: LDtkProject

    the project the level or the world belongs to

    rows: number = 0

    its height in cells of the project's default grid

    stayed: Map<string, Renderable> = ...

    the persistent entities that stayed when their level was taken out, by their unique id in LDtk

    tileheight: number

    the size of a cell of the project's default grid, in pixels

    tilewidth: number

    the size of a cell of the project's default grid, in pixels

    width: number = 0

    its width, in pixels

    x: number = 0

    its left edge in the container it is added to, in pixels: 0 for a level, LDtk's world coordinate for a world

    y: number = 0

    its top edge in the container it is added to, in pixels

    • the values of an IntGrid layer of a level in the game

      Parameters

      • level: string

        the level's identifier in LDtk, or its iid

      • name: string

        the layer's identifier in LDtk

      Returns IntGrid | undefined

      the grid, or undefined if the level is not in the game or has no such layer

    • whether a level of the world is in the game now

      Parameters

      • identifier: string

        the level's identifier in LDtk, or its iid

      Returns boolean

      true if it is

    • the levels of the world an area touches

      Parameters

      • x: number

        the area's left edge, in pixels

      • y: number

        the area's top edge, in pixels

      • width: number = 0

        the area's width (0 for a point)

      • height: number = 0

        the area's height (0 for a point)

      • Optionaldepth: number

        only the levels of this depth: in a world whose levels are stacked (LDtk's "world depth"), the ones the player is among

      Returns LDtkLevelInfo[]

      the levels

    • add a level of the world to the game, where LDtk puts it

      Parameters

      • identifier: string

        the level's identifier in LDtk, or its iid

      Returns boolean

      false if it was there already, or the world is not loaded

    • add the level or the world to the container, as a Tiled map is

      Parameters

      • container: Container

        the container

      • options: LDtkLoadOptions

        LDtk's load options

      • backgroundColor: string

        the color behind it

      • add: () => void

        adds its layers, bodies and entities

      Returns void

    • Keep in the game the levels within reach of an area, and only those: the ones the area touches once grown by margin are added, the others taken out. Call it as the player moves, with the camera's view or the player's own box, for a world too large to hold at once.

      Parameters

      • x: number

        the area's left edge, in pixels

      • y: number

        the area's top edge, in pixels

      • width: number

        the area's width

      • height: number

        the area's height

      • margin: number = 0

        how far past the area a level is kept, in pixels

      • Optionaldepth: number

        keep the levels of this depth only: the levels of the other depths are taken out, which is how a world whose levels are stacked shows the ones the player is among

      Returns { loaded: string[]; unloaded: string[] }

      the identifiers of the levels added and of those taken out

    • Take a level of the world out of the game: its layers, its bodies and its entities. An entity that is persistent (Renderable#isPersistent), as a player is, stays in the game, and is not built again when its level comes back.

      Parameters

      • identifier: string

        the level's identifier in LDtk, or its iid

      Returns boolean

      false if it was not there