Constructor
new Sprite(logId)
Construct a sprite.
Parameters:
| Name | Type | Description |
|---|---|---|
logId |
string | ID used for logging purposes only. |
- Implements:
- Source:
Members
adjuster :module:hcje/sprites.BaseSpriteAdjuster
Adjuster used by the sprite. When changing the property, if there is a current adjuster, it is automatically marked as complete with an undefined reason; however, its onCompletion function will not be called. If you need the function to be called, call the current adjuster's markComplete method first before changing this property.
Type:
- Source:
autoFlipX :boolean
Flip in x direction when velocity is negative.
Type:
- boolean
- Source:
autoFlipY :boolean
Flip in y direction when velocity is negative.
Type:
- boolean
- Source:
(readonly) bounds :module:hcje/utils~RectData
Bounding rectangle for the sprite.
Type:
- Source:
collisionDetector :module:hcje/collisions.CollisionDetector
Type:
- Source:
custom :*
Custom property which can be used by the owner for anything. It is not initialised to anything and is guaranteed not to be used by the class for anything.
Type:
- *
- Source:
dimensions :module:hcje/utils~Dimensions
Dimensions of the sprite.
Type:
- Source:
dynamics :module:hcje/sprites.Dynamics
Dynamics object. If set, its update
Type:
- Source:
(readonly) frameData :module:hcje/sprites~FrameData
The current frame data.
Type:
- Source:
logId :string
Id used for debugging purposes.
Type:
- string
- Source:
opacity :number
Opacity of sprite 0 to 1.
Type:
- number
- Source:
position :module:hcje/utils~PositionData
The current sprite position. Changes are instantaneous and can later be modified by the dynamics. Position is the top-left corner of the sprite.
Type:
- Source:
state :string
The current state property. When setting, the state must exist in the existing map of states, otherwise the attempt to set is ignored. It is not possible to set an illegal state.
Type:
- string
- Source:
Methods
addFollower(sprite, relativePositionopt)
Add a follower. Followers are automatically updated by the parent sprite so should not be separately added to
an Animator. They will follow this sprite and be killed when this sprite is killed.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
sprite |
module:hcje/sprites.Sprite | sprite to treat as a follower. |
||
relativePosition |
module:hcje/utils~PositionData |
<optional> |
{x:0, y: 0, angle:0} | position relative to this sprite. |
- Source:
isKilled() → {boolean}
Check if the sprite has been killed.
- Implements:
- Source:
Returns:
- Type
- boolean
kill()
Kill the target.
- Implements:
- Source:
removeFollower(sprite)
Free a follow. It is removed from the map of followers. Note it is the caller's responsibilty to delete or kill the sprite. This method, merely removes it from the parent's control.
Parameters:
| Name | Type | Description |
|---|---|---|
sprite |
module:hcje/sprites.Sprite | sprite to remove. |
- Source:
setStateFrames(stateName, stateConfig)
Set the frames for a specified state.
Parameters:
| Name | Type | Description |
|---|---|---|
stateName |
string | Key name for this animation. |
stateConfig |
module:hcje/sprites~AnimationStateConfig | State configuration. |
- Source:
update(timestamp, deltaSeconds)
Update function called by the Animator.
Parameters:
| Name | Type | Description |
|---|---|---|
timestamp |
DOMHighResTimeStamp | Timestamp in milliseconds |
deltaSeconds |
number | Elapsed time in seconds since previous update called. |
- Implements:
- Source:
(static) deriveWalk(dynamics, distPerFrame)
Interval derivation function to assist with calculation of automatic walk speeds. Typically used for
module:hcje/sprites~deriveInterval callbacks. E.g. (dynamics) => Sprite.deriveWalk(dynamics, DPF) where
DPF is the number of pixels the frame animation would move per frame.
Parameters:
| Name | Type | Description |
|---|---|---|
dynamics |
module:hcje/sprites.Dynamics | Sprite's current dynamics value. |
distPerFrame |
number | The number of pixels the animation frames are drawn to move. |
- Source: