melonJS
    Preparing search index...

    Function registerFormat

    • Register a level format: what level.add makes a level of that format from, so that level.load, level.next, level.reload and a Trigger work with it as they do with a Tiled map. A loader for another map editor's files registers one, then calls level.add(format, levelId) for each level it has read.

      create(levelId) returns the level object, which the director keeps and asks for two things:

      • addTo(container, options): add everything the level holds to the container. options are the ones given to level.load; the container has been emptied first.
      • destroy(): let go of what addTo built, when another level is loaded. The level is loaded again later with another addTo.

      It is made when the level is added, which is usually while assets are still loading: keep create cheap, and read images and build layers in addTo. A nextobjectid number on it, if any, is where the ids of the objects made at run time start.

      Parameters

      • format: string

        the name of the format, as given to level.add

      • definition: { create: Function; loadOptions?: string[] }

        how levels of this format are made

        • create: Function

          create(levelId), returning the level object

        • OptionalloadOptions?: string[]

          the names of the options addTo reads beyond container, onLoaded and async, so that a Trigger forwards them from its settings

      Returns void

      when the format is already registered, or create is not a function

      // levels kept by a parser of your own, registered with `loader.setParser`
      level.registerFormat("rooms", {
      create: (levelId) => new Room(rooms.get(levelId)),
      });
      // then, for each room the parser has read:
      level.add("rooms", "cellar");
      // and in the game:
      level.load("cellar");