API Documentation for: 0.11.8
Show:

platypus.components.StateRender Class

Module: platypus

Available since 0.9.0

This component is typically added to an entity automatically by a render component. It handles mapping entity states to playable animations.

Methods

'animation-ended'

(
  • animation
)

On receiving this event, the component checks for any waiting animations and begins playing them if so.

Parameters:

  • animation String

    The animation that completed.

'state-changed'

()

Defined in 'state-changed':138

This listens for the entity state to change and will update the currently playing animation.

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]".

update-animation

(
  • playing
)

This checks to determine whether another animation should begin playing.

Parameters:

  • playing Boolean

    Whether the new animation should play or pause on the first frame.

Properties

animationMap

Object

Defined in animationMap:60

An object containg key-value pairs that define a mapping from entity states to the animation that should play. The list is processed from top to bottom, so the most important actions should be listed first (for example, a jumping animation might take precedence over an idle animation). If not specified, an 1-to-1 animation map is created from the list of animations in the sprite sheet definition using the animation names as the keys.

"animationMap":{ "standing": "default-animation" // On receiving a "standing" event, or when this.owner.state.standing === true, the "default" animation will begin playing. "ground,moving": "walking", // Comma separated values have a special meaning when evaluating "state-changed" messages. The above example will cause the "walking" animation to play ONLY if the entity's state includes both "moving" and "ground" equal to true. "ground,striking": "swing!", // Putting an exclamation after an animation name causes this animation to complete before going to the next animation. This is useful for animations that would look poorly if interrupted. "default": "default-animation" // Optional. "default" is a special property that matches all states. If none of the above states are valid for the entity, it will use the default animation listed here. }

Default: null

component

Component

Defined in component:76

Available since 0.9.2

Sets a component that this component should be connected to.

Default: null

forcePlayThrough

Boolean

Defined in forcePlayThrough:86

Optional. Forces animations to complete before starting a new animation. Defaults to false.

Default: false

Events

'play-animation'

Defined in 'play-animation':37

On entering a new animation-mapped state, this component triggers this event to play an animation.

Event Payload:

  • animation String

    Describes the animation to play.

  • restart Boolean

    Whether to restart a playing animation.

'stop-animation'

Defined in 'stop-animation':47

On attaining an animation-mapped state, this component triggers this event to stop a previous animation.

Event Payload:

  • animation String

    Describes the animation to stop.