API Documentation for: 0.11.8
Show:

platypus.components.TiledLoader Class

This component is attached to a top-level entity (loaded by the Scene) and, once its peer components are loaded, ingests a JSON file exported from the Tiled map editor and creates the tile maps and entities. Once it has finished loading the map, it removes itself from the list of components on the entity.

This component requires an EntityContainer since it calls entity.addEntity() on the entity, provided by EntityContainer.

This component looks for the following entities, and if not found will load default versions:

   {
                               "render-layer": {
                                   "id": "render-layer",
                                   "components":[{
                                       "type": "RenderTiles",
                                       "spriteSheet": "import",
                                       "imageMap":    "import",
                                       "entityCache": true
                                   }]
                               },
                               "collision-layer": {
                                   "id": "collision-layer",
                                   "components":[{
                                       "type": "CollisionTiles",
                                       "collisionMap": "import"
                                   }]
                               },
                               "image-layer": {
                                   "id": "image-layer",
                                   "components":[{
                                       "type": "RenderTiles",
                                       "spriteSheet": "import",
                                       "imageMap":    "import"
                                   }]
                               }
                           }

Methods

'load-level'

(
  • levelData
  • callback
)

Defined in 'load-level':506

If manuallyLoad is set, the component will wait for this message before loading the Tiled map JSON definition.

Parameters:

  • levelData Object
    • level String | Object

      The level to load.

    • [persistentData] Object optional

      Information passed from the last scene.

  • callback Function

    The function to call once the level is loaded.

'scene-loaded'

(
  • persistentData
  • holds
)

Defined in 'scene-loaded':486

On receiving this message, the component commences loading the Tiled map JSON definition. Once finished, it removes itself from the entity's list of components.

Parameters:

  • persistentData Object

    Data passed from the last scene into this one.

    • level Object

      A level name or definition to load if the level is not already specified.

  • holds platypus.Data

    An object that handles any holds on before making the scene live.

    • count Number

      The number of holds to wait for before triggering "scene-live"

    • release Function

      The method to trigger to let the scene loader know that one hold has been released.

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.

decodeLayer

(
  • layer
)
Object chainable

Defined in decodeLayer:1105

Available since 0.7.1

This method decodes a Tiled layer and sets its data to CSV format.

Parameters:

  • layer Object

    An object describing a Tiled JSON-exported layer.

Returns:

Object:

The same object provided, but with the data field updated.

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

entityPositionX

String

Defined in entityPositionX:450

Can be "left", "right", or "center". Defines where entities registered X position should be when spawned. Available on the entity as entity.entityPositionX.

Default: "center"

entityPositionY

String

Defined in entityPositionY:459

Can be "top", "bottom", or "center". Defines where entities registered Y position should be when spawned. Available on the entity as entity.entityPositionY.

Default: "bottom"

images

Array

Defined in images:384

If specified, the referenced images are used as the game sprite sheets instead of the images referenced in the Tiled map. This is useful for using different or better quality art from the art used in creating the Tiled map.

Default: null

imagesScale

Number

Defined in imagesScale:441

If images are provided, this property sets the scale of the art relative to world coordinates. Available on the entity as entity.imagesScale.

Default: 1

layerIncrement

Number

Defined in layerIncrement:393

Adds a number to each additional Tiled layer's z coordinate to maintain z-order. Defaults to 1000.

Default: 1000

level

String

Defined in level:423

Specifies the JSON level to load. Available on the entity as entity.level.

Default: null

manuallyLoad

Boolean

Defined in manuallyLoad:468

Whether to wait for a "load-level" event before before loading. Available on the entity as entity.manuallyLoad.

Default: false

offsetMap

Boolean

Defined in offsetMap:365

Available since 0.7.5

This causes the entire map to be offset automatically by an order of magnitude higher than the height and width of the world so that the number of digits below zero is constant throughout the world space. This fixes potential floating point issues when, for example, 97 is added to 928.0000000000001 giving 1025 since a significant digit was lost when going into the thousands.

Default: false

separateTiles

Boolean

Defined in separateTiles:402

Keeps the tile maps in separate render layers. Default is 'false' to for better optimization.

Default: false

showCollisionTiles

Boolean

If set to true and if the game is running in debug mode, this causes the collision layer to appear.

Default: false

spriteSheet

String | Object

Defined in spriteSheet:411

Available since 0.6.6

If a particular sprite sheet should be used that's not defined by the level images themselves. This is useful for making uniquely-themed variations of the same level. This is overridden by "spriteSheet": "import" in the "render-layer" Entity definition, so be sure to remove that when setting this property.

Default: null

unitsPerPixel

Number

Defined in unitsPerPixel:432

Sets how many world units in width and height correspond to a single pixel in the Tiled map. Default is 1: One pixel is one world unit. Available on the entity as entity.unitsPerPixel.

Default: 1

Events

'level-loading-progress'

Defined in 'level-loading-progress':1082

Available since 0.8.3

As a level is loaded, this event is triggered to show progress.

Event Payload:

  • message platypus.Data

    Contains progress data.

    • count Number

      The number of loaded entities.

    • progress Number

      A fraction of count / total.

    • total Number

      The total number of entities being loaded by this component.

'world-loaded'

Defined in 'world-loaded':87

Once finished loading the map, this message is triggered on the entity to notify other components of completion.

Event Payload:

  • message platypus.Data

    World data.

    • level Object

      The Tiled level data used to load the level.

    • width Number

      The width of the world in world units.

    • height Number

      The height of the world in world units.

    • tile platypus.AABB

      Dimensions of the world tiles.

    • world platypus.AABB

      Dimensions of the world.

    • camera platypus.Entity

      If a camera property is found on one of the loaded entities, this property will point to the entity on load that a world camera should focus on.