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:
|
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. |
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
|
Returns:
The new clip that was added.
clip(name) → {pc.SpriteAnimationClip}
Get an animation clip by name.
Parameters:
Name | Type | Description |
---|---|---|
name |
String | The name of the clip. |
Returns:
The clip.
pause()
Pauses the current animation clip.
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. |
Returns:
The clip that started playing.
removeClip(name)
Removes a clip by name.
Parameters:
Name | Type | Description |
---|---|---|
name |
String | The name of the animation clip to remove. |
resume()
Resumes the current paused animation clip.
stop()
Stops the current animation clip and resets it to the first frame.
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 |
loop
Fired when an animation clip reached the end of its current loop.
Parameters:
Name | Type | Description |
---|---|---|
clip |
pc.SpriteAnimationClip | The clip |
pause
Fired when an animation clip is paused.
Parameters:
Name | Type | Description |
---|---|---|
clip |
pc.SpriteAnimationClip | The clip that was paused |
play
Fired when an animation clip starts playing
Parameters:
Name | Type | Description |
---|---|---|
clip |
pc.SpriteAnimationClip | The clip that started playing |
resume
Fired when an animation clip is resumed.
Parameters:
Name | Type | Description |
---|---|---|
clip |
pc.SpriteAnimationClip | The clip that was resumed |
stop
Fired when an animation clip is stopped.
Parameters:
Name | Type | Description |
---|---|---|
clip |
pc.SpriteAnimationClip | The clip that was stopped |