Module providing handling for sprite sheets typically created by TexturePacker. The sprite sheet must have been exported using the JSON (Hash) format: trimming and sprite rotation within the sheet is NOT supported. Only part of the information in the Hash format JSON file is used. CodeAndWeb, the creators of TexturePacker also have a free online version Free Sprite Sheet Packer which can also be used but without the efficiency of the full version. If you are not using TexturePacker, you can create the JSON file manually by referring to PackedSpritesTextureData for details of the object to be encoded in the file.
- Source:
Classes
- Animator
- BaseSpriteAdjuster
- Bouncer
- DomImageSpriteFactory
- DomImageSpriteRenderer
- DomTextSpriteRenderer
- Dynamics
- ReachTargetXY
- Sprite
- TerminateOutOfBounds
- TextureManager
Interfaces
Members
(static, constant) CycleType :CycleType
Type of animation cycles.
Type:
- CycleType
Properties:
| Name | Type | Description |
|---|---|---|
NONE |
CycleTypeEnumValue | No cycling of the animation. |
LOOP |
CycleTypeEnumValue | When the last frame is reached, jump back to the first frame and continue. |
OSCILLATE |
CycleTypeEnumValue | When the last frame is reached, animate back down the frames to the first frame and continue. |
STOP |
CycleTypeEnumValue | Stop animating when the last frame is reached. |
- Source:
Methods
(static) createTextSprite(container, txt, options) → {module:hcje/sprites.Sprite}
Create a text sprite.
Parameters:
| Name | Type | Description | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
container |
Element | ElementWrapper | The sprite is appended to the container. |
|||||||||
txt |
string | The contents of the sprite. |
|||||||||
options |
Object | Configuration options. Properties
|
- Source:
Returns:
(static) loadSpriteSheet(dataUrl, imagesUrl, busyIndicatoropt) → {Promise}
Load the sprite sheet.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
dataUrl |
string | Url used to retrieve the spritesheet data file. |
|
imagesUrl |
string | Url used to retrieve the associated spritesheet. |
|
busyIndicator |
module:hcje/domTools~BusyIndicator |
<optional> |
Indicator to show loading. |
- Source:
Returns:
Fulfils to module:hcje/sprites.TextureManager; undefined on error.
- Type
- Promise
(inner) loadImage(source) → {Promise}
Load an image.
Parameters:
| Name | Type | Description |
|---|---|---|
source |
string | Source url for the image. |
- Source:
Returns:
Fulfils to HTMLImageElement once the image has been loaded.
- Type
- Promise
Type Definitions
AnimationStateConfig
Configuration for an animation state.
Type:
- Object
Properties:
| Name | Type | Description |
|---|---|---|
interval |
number | module:hcje/sprites~deriveInterval | The animation interval in milliseconds or function to derive it. |
cycleType |
CycleTypeEnumValue | Type of loop. Defaults CycleType.LOOP. |
- Source:
CycleTypeEnumValue
Type of animation cycle.
Type:
- number
- Source:
FrameData
Data describing position and dimensions of a frame.
Type:
- Object
Properties:
| Name | Type | Attributes | Description |
|---|---|---|---|
x |
number | left position. |
|
y |
number | top position. |
|
width |
number | width of sprite. |
|
height |
number | height of sprite. |
|
flipX |
boolean |
<optional> |
sprite is flipped in its unrotated x direction. |
flipY |
boolean |
<optional> |
sprite is flipped in its unrotated y direction. |
- Source:
PackedSpritesFrameData
Frame object encoded using JSON within a texture's data file to provide information about an individual frame.
Type:
- Object
Properties:
| Name | Type | Description | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
frame |
Object | information locating the sprite image in the texture. Properties
|
- Source:
PackedSpritesTextureData
Object encoded using JSON within a texture's data file and used for extrating individual frames from the texture file. The object is a subset of the object contained within the JSON (Hash) data file created by TexturePacker.
Type:
- Object
Properties:
| Name | Type | Description |
|---|---|---|
frames |
Object.<string, module:hcje/sprites~PackedSpritesFrameData> | root object containing individual data for extracting individual sprite images from a texture. |
- Source:
deriveInterval(dynamics) → {number}
Automatic calculation of the animation interval. This adjusts the interval based on the current dynamics and is typically used to adjust a sprite's animation interval based on its walking speed.
Parameters:
| Name | Type | Description |
|---|---|---|
dynamics |
module:hcje/sprites.Dynamics | The current dynamics. |
- Source:
Returns:
Required interval in ms.
- Type
- number
frameNameGenerator(baseName, state, index) → {string}
Frame name generator for sprite names in a texture.
Parameters:
| Name | Type | Description |
|---|---|---|
baseName |
string | The string from which the final name is created. |
state |
string | The state of the sprite. E.g. idle, walking etc. |
index |
number | The 0 based frame index. |
- Source:
Returns:
The frame name which corresponds to the key in the frames object in
PackedSpritesTextureData JSON file.
- Type
- string
onAdjustmentComplete(success, reasonopt)
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
success |
boolean | True if the adjustment was regarded as completed successfully. |
|
reason |
* |
<optional> |
Argument containing information about the reason for completion. This reflects the value passed to the markComplete method. It could be undefined depending on the implementation. |
- Source: