API Documentation for: 0.11.8
Show:

platypus.components.AIChaser Class

This component acts as a simple AI that will chase another entity.

Methods

'handle-ai'

()

Defined in 'handle-ai':75

This AI listens for a step message triggered by its entity parent in order to perform its logic on each tick.

'load'

()

Defined in 'load':57

This component listens for this event to initialize movement.

'set-target'

(
  • entity
)

Defined in 'set-target':110

On receiving this message, the component will change its target and begin chasing the new entity.

Parameters:

'set-target-offset'

(
  • offset
)

On receiving this message, the component will change its target offset.

Parameters:

  • offset Object | Vector

    Sets the chased entity's offset to the provided offset.

    • x Number

      The offset along the x-axis.

    • y Number

      The offset along the y-axis.

'start-chasing'

(
  • [entity]
)

Defined in 'start-chasing':135

On receiving this message, the component will begin chasing the entity.

Parameters:

'stop-chasing'

()

Defined in 'stop-chasing':148

On receiving this message, the component will cease chasing the entity.

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

accelerate

Boolean

Defined in accelerate:19

Sets whether the speed property should enact acceleration upon the entity rather than velocity.

Default: false

chasing

Boolean

Defined in chasing:28

Whether the entity is in a chasing state.

Default: true

speed

Number

Defined in speed:39

Sets the velocity of the entity. This property is accessible on the entity as entity.speed.

Default: 0.3

Events

'chase'

Defined in 'chase':100

This event is triggered whenever the entity begins chasing another entity or stops chasing another entity.

Event Payload:

  • chasing Boolean

    Whether the entity is chasing another entity.