Class: SpriteComponent

pc.SpriteComponent

Enables an Entity to render a simple static sprite or sprite animations.

Constructor

new SpriteComponent(system, entity)

Parameters:
Name Type Description
system pc.SpriteComponentSystem The ComponentSystem that created this Component
entity pc.Entity The Entity that this Component is attached to.
Properties:
Name Type Description
type String The type of the SpriteComponent. Can be one of the following:
  • pc.SPRITETYPE_SIMPLE: The component renders a single frame from a sprite asset.
  • pc.SPRITETYPE_ANIMATED: The component can play sprite animation clips.
frame Number The frame counter of the sprite. Specifies which frame from the current sprite asset to render.
spriteAsset Number The id of the sprite asset to render. Only works for pc.SPRITETYPE_SIMPLE types.
sprite pc.Sprite The current sprite.
color pc.Color The color tint of the sprite.
opacity Number The opacity of the sprite.
flipX Boolean Flip the X axis when rendering a sprite.
flipY Boolean Flip the Y axis when rendering a sprite.
clips Object A dictionary that contains pc.SpriteAnimationClips.
currentClip pc.SpriteAnimationClip The current clip being played.
speed Number A global speed modifier used when playing sprite animation clips.
batchGroupId Number Assign sprite to a specific batch group (see pc.BatchGroup). Default value is -1 (no group).
autoPlayClip String The name of the clip to play automatically when the component is enabled and the clip exists.
layers Array An array of layer IDs (pc.Layer#id) to which this sprite should belong.
drawOrder Number The draw order of the component. A higher value means that the component will be rendered on top of other components in the same layer.
Source:

Extends

Methods

addClip(data) → {pc.SpriteAnimationClip}

Creates and adds a new pc.SpriteAnimationClip to the component's clips.
Parameters:
Name Type Description
data Object Data for the new animation clip.
Properties
Name Type Attributes Description
name String <optional>
The name of the new animation clip.
fps Number <optional>
Frames per second for the animation clip.
loop Object <optional>
Whether to loop the animation clip.
spriteAsset Number <optional>
The id of the sprite asset that this clip will play.
Source:
Returns:
The new clip that was added.
Type
pc.SpriteAnimationClip

clip(name) → {pc.SpriteAnimationClip}

Get an animation clip by name.
Parameters:
Name Type Description
name String The name of the clip.
Source:
Returns:
The clip.
Type
pc.SpriteAnimationClip

pause()

Pauses the current animation clip.
Source:

play(name) → {pc.SpriteAnimationClip}

Plays a sprite animation clip by name. If the animation clip is already playing then this will do nothing.
Parameters:
Name Type Description
name String The name of the clip to play.
Source:
Returns:
The clip that started playing.
Type
pc.SpriteAnimationClip

removeClip(name)

Removes a clip by name.
Parameters:
Name Type Description
name String The name of the animation clip to remove.
Source:

resume()

Resumes the current paused animation clip.
Source:

stop()

Stops the current animation clip and resets it to the first frame.
Source:

Events

end

Fired when an animation clip stops playing because it reached its ending.
Parameters:
Name Type Description
clip pc.SpriteAnimationClip The clip that ended
Source:

loop

Fired when an animation clip reached the end of its current loop.
Parameters:
Name Type Description
clip pc.SpriteAnimationClip The clip
Source:

pause

Fired when an animation clip is paused.
Parameters:
Name Type Description
clip pc.SpriteAnimationClip The clip that was paused
Source:

play

Fired when an animation clip starts playing
Parameters:
Name Type Description
clip pc.SpriteAnimationClip The clip that started playing
Source:

resume

Fired when an animation clip is resumed.
Parameters:
Name Type Description
clip pc.SpriteAnimationClip The clip that was resumed
Source:

stop

Fired when an animation clip is stopped.
Parameters:
Name Type Description
clip pc.SpriteAnimationClip The clip that was stopped
Source: