API Documentation for: 0.11.8
Show:

platypus.components.LevelBuilder Class

This component works in tandem with 'TiledLoader by taking several Tiled maps and combining them before TiledLoader processes them. Tiled maps must use the same tilesets for this to function correctly.

Note: Set "manuallyLoad" to true in the TiledLoader component JSON definition so that it will wait for this component's "load-level" call.

Methods

'scene-loaded'

(
  • persistentData
)

Defined in 'scene-loaded':216

When the scene has loaded, LevelBuilder compiles the level based on the template and pieces and sends it to the TiledLoader.

Parameters:

  • persistentData Object

    The persistent data from the previous scene.

addEventListener

(
  • event
  • callback
)
Function private
This method adds an event listener to the entity.

Parameters:

  • event String
    The event that this component should listen for.
  • callback Function
    The handler for the event.

Returns:

Function: handler A reference to the bound handler.

addMethod

(
  • name
  • func
)
private
This method adds a method to the entity.

Parameters:

  • name String
    The name of the method. For example, if name is "turnYellow", the method is accessible on the entity as entity.turnYellow().
  • func Function
    The function describing the method.

destroy

() private

Inherited from platypus.Component: destroy:54

This method cleans up listeners and methods that this component added to the entity. It should never be called by the component itself. Call this.owner.removeComponent(this) instead.

getAssetList

(
  • definition
  • properties
  • defaultProperties
)
Array
This method can be overwritten to provide the list of assets this component requires. This method is invoked when the list of game scenes is created to determine assets for each scene.

Parameters:

  • definition Object
    The definition for the component.
  • properties Object
    The properties of the Entity.
  • defaultProperties Object
    The default properties of the Entity.

Returns:

Array: A list of the necessary assets to load.

getLateAssetList

(
  • data
)
Array
This method can be overwritten to provide the list of assets this component requires. This method is invoked when the list of game scenes is created to determine assets for each scene.

Parameters:

  • data Object
    Scene data that affects the list of assets.

Returns:

Array: A list of the necessary assets to load.

removeEventListener

(
  • event
  • callback
)
private
This method removes an event listener from the entity.

Parameters:

  • event String
    The event for which to remove a listener.
  • callback Function
    The listener to remove. If not supplied, all event listeners for the provided event are removed.

removeEventListeners

(
  • [listeners]
)
private
This method removes multiple event listeners from the entity.

Parameters:

  • [listeners] Array optional
    The list of listeners to remove. If not supplied, all event listeners are removed.

removeMethod

(
  • name
)
private
This method removes a method from the entity.

Parameters:

  • name String
    The name of the method to be removed.

toJSON

() Object

Inherited from platypus.Component: toJSON:45

Available since 0.11.0

Returns a JSON object describing the component.

Returns:

Object: Returns a JSON definition that can be used to recreate the component.

toString

() String
Returns a string describing the component.

Returns:

String: Returns the component type as a string of the form "[Component ComponentType]".

Properties

levelPieces

Object

Defined in levelPieces:191

This is an object of key/value pairs listing the pieces that map to an id in the level template. The value can be specified as a string or array. A piece will be randomly chosen from an array when that idea is used. If levelPieces is not defined, ids in the template map directly to level names.

 "levelPieces": {
                                                 "start"  : "start-map",
                                                 "end"      : "end-map",
                                                 "forest" : ["forest-1", "forest-2", "forest-3"]
                                             }

Default: null

levelTemplate

Array

Defined in levelTemplate:181

A 1D or 2D array of level piece ids. The template defines how the pieces will be arranged and which pieces can be used where. The template must be rectangular in dimensions.

 "levelTemplate": [ ["start", "forest"], ["forest", "end"] ]

Default: null

useUniques

Boolean

Defined in useUniques:173

If true, no single map piece is used twice in the creation of the combined map.

Default: true

Events

'load-level'

Defined in 'load-level':278

Dispatched when the scene has loaded and the level has been composited so TileLoader can begin loading the level.

Event Payload:

  • data Object
    • level Object

      An object describing the level dimensions, tiles, and entities.

    • persistentData Object

      The persistent data passed from the last scene. We add levelBuilder data to it to pass on.

      • levelTemplate Object
        A 1D or 2D array of level piece ids. The template defines how the pieces will be arranged and which pieces can be used where. The template must be rectangular in dimensions.
      • levelPieces Object
        An object of key/value pairs listing the pieces that map to an id in the level template.
      • useUniques Boolean
        If true, no single map piece is used twice in the creation of the combined map.