API Documentation for: 0.11.8
Show:

platypus.components.RenderAnimation Class

Module: platypus

Available since 0.10.0

This component is attached to entities that will appear in the game world. It renders a static or animated image. It listens for messages triggered on the entity or changes in the logical state of the entity to play a corresponding animation.

Note: This component requires assets published using PixiAnimate.

Methods

'camera-update'

(
  • camera.viewport
)

Defined in 'camera-update':354

Listens for this event to determine whether this sprite is visible.

Parameters:

'handle-render'

(
  • renderData
)

Defined in 'handle-render':382

The render update message updates the animation.

Parameters:

  • renderData Object

    Data from the render handler

    • container PIXI.Container

      The parent container.

'handle-render-load'

(
  • handlerData
)

A setup message used to add the animation to the stage. On receiving this message, the component sets its parent container to the stage contained in the message if it doesn't already have one.

Parameters:

  • handlerData Object

    Data from the render handler

    • container PIXI.Container

      The parent container.

'hide-animation'

()

This event makes the animation invisible.

'play-animation'

(
  • [animation]
)

Starts the animation.

Parameters:

  • [animation] String optional

    The animation to play. If not specified, this method simply unpauses the current animation.

'set-mask'

(
  • mask
)

Defined in 'set-mask':416

Defines the mask on the animation. If no mask is specified, the mask is set to null.

Parameters:

  • mask Object

    The mask. This can specified the same way as the 'mask' parameter on the component.

'show-animation'

()

This event makes the animation visible.

'stop-animation'

(
  • [animation]
)

Stops the animation.

Parameters:

  • [animation] String optional

    The animation to show and pause. If not specified, this method simply pauses the current 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]".

Properties

animation

String

Defined in animation:68

This sets the PixiAnimate animation to play. This is typically of the form "library.asset" as defined by the PixiAnimate publish settings.

Default: ""

animationMap

Object

Defined in animationMap:77

Optional. An object containg key-value pairs that define a mapping from triggered events or 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.
                                            }
                                            

This data is used to create EventRender or StateRender components on the entity if the eventBased or stateBased properties are set to true.

Default: null

eventBased

Boolean

Defined in eventBased:154

Optional. Specifies whether this component should create an EventRender component to listen to events matching the animationMap to animate. Set this to true if the component should animate for on events. Default is false.

Default: false

framerate

Number

Defined in framerate:95

Available since 0.10.2

The framerate at which the animation should play.

Default: 24

interactive

Boolean | Object

Defined in interactive:125

Available since 0.9.0

Defines whether the entity will respond to touch and click events. Setting this value will create an Interactive component on this entity with these properties. For example:

"interactive": { "hover": false, "hitArea": { "x": 10, "y": 10, "width": 40, "height": 40 } }

Default: false

mask

Object

Defined in mask:105

Optional. A mask definition that determines where the image should clip. A string can also be used to create more complex shapes via the PIXI graphics API like: "mask": "r(10,20,40,40).dc(30,10,12)". Defaults to no mask or, if simply set to true, a rectangle using the entity's dimensions.

"mask": { "x": 10, "y": 10, "width": 40, "height": 40 },

-OR-

"mask": "r(10,20,40,40).dc(30,10,12)"

Default: null

offsetZ

Number

Defined in offsetZ:190

The offset of the z-index of the sprite from the entity's z-index.

Default: 0

regX

Number

Defined in regX:172

Determines the x origin of the animation.

Default: 0

regY

Number

Defined in regY:181

Determines the y origin of the animation.

Default: 0

scaleX

Number

Defined in scaleX:200

The X scaling factor for the image.

Default: 1

scaleY

Number

Defined in scaleY:209

The Y scaling factor for the image.

Default: 1

stateBased

Boolean

Defined in stateBased:163

Optional. Specifies whether this component should create a StateRender component to handle changes in the entity's state that match the animationMap to animate. Set this to true if the component should animate based on this.owner.state. Default is true.

Default: true

visible

Boolean

Defined in visible:145

Optional. Whether this object is visible or not. To change the visible value dynamically set this.owner.state.visible to true or false.

Default: false

x

Number

Defined in x:218

The x position of the entity.

Default: 0

y

Number

Defined in y:227

The y position of the entity.

Default: 0

z

Number

Defined in z:236

The z position of the entity.

Default: 0

Events

'animation-ended'

This event fires each time an animation completes.

Event Payload:

  • animation String

    The id of the animation that ended.

'input-on'

Defined in 'input-on':320

This event is triggered once the RenderSprite is ready to handle interactivity.