Class: Sprite

hcje/sprites.Sprite(logId)

Sprite class.

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:

dimensions :module:hcje/utils~Dimensions

Dimensions of the sprite.

Type:
Source:

dynamics :module:hcje/sprites.Dynamics

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

isKilled() → {boolean}

Check if the sprite has been killed.

Implements:
Source:
Returns:
Type
boolean

kill()

Kill the target.

Implements:
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: