API Documentation for: 1.0.1
Show:

platypus.components.RelativePosition Class

Module: platypus

Available since 1.0.0

This component positions an entity relative to the camera viewport, according to left, top, right, and left properties.

Methods

'camera-update'

(
  • camera
)

Defined in 'camera-update':125

Available since 0.9.0

This component listens for camera updates to reposition the entity if its bottom, left, right, or top properties have been set.

Parameters:

  • camera platypus.Data

    Camera update information

    • viewport platypus.AABB

      The bounding box describing the camera viewport location in the world.

'handle-logic'

()

Defined in 'handle-logic':105

This component uses location updates to reposition the entity if its bottom, left, right, or top properties have been set.

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

bottom

Number

Defined in bottom:40

This sets the distance in world units from the bottom of the camera's world viewport. If set, it will override the entity's y coordinate. This property is accessible on the entity as entity.bottom.

Default: null

cameraSizes

Array

Defined in cameraSizes:19

This optional array sets varying properties depending on the aspect ratio of the camera. This is useful if the camera aspect ratio varies greatly and entities must be repositioned accordingly.

In this example, the entity maintains a particular horizontal location until the camera viewport becomes narrower than 2:1, at which point it maintains a particular left value:

 "cameraSizes": [{
                                                 "minRatio": 2, // This block applies for wide aspect ratios until 2:1 is reached.
                                                 "x": -1226
                                             }, {
                                                 "minRatio": 0, // This block applies for everything else.
                                                 "left": 130
                                             }]

Default: null

left

Number

Defined in left:49

This sets the distance in world units from the left of the camera's world viewport. If set, it will override the entity's x coordinate. This property is accessible on the entity as entity.left.

Default: null

right

Number

Defined in right:58

This sets the distance in world units from the right of the camera's world viewport. If set, it will override the entity's x coordinate. This property is accessible on the entity as entity.right.

Default: null

top

Number

Defined in top:67

This sets the distance in world units from the top of the camera's world viewport. If set, it will override the entity's y coordinate. This property is accessible on the entity as entity.top.

Default: null

x

Number

Defined in x:76

This sets the x coordinate for the entity. It is overridden by left and right properties if supplied.

Default: 0

y

Number

Defined in y:85

This sets the y coordinate for the entity. It is overridden by top and bottom properties if supplied.

Default: 0