Constructor
new Animation(frames, options)
| Name | Type | Description |
|---|---|---|
frames | Array.<AnimationFrame> | The frames of the animation |
options | AnimationOptions | animation options |
- Source
// ...
// Create a sprite with the image "player.png" in the top left corner
const frames = [{
image: { type: 'Image', value: new gameify.Image("player_idle1.png") },
position: { type: 'Vector2d', value: new gameify.Vector2d(0, 2) },
}, // ... more frames
];
let myAnimation = new gameify.Animation(frames, { duration: 200, loop: true });
mySprite.animator.set('idle', myAnimation);
// ...
myScene.onUpdate(() => {
if (mySprite.velocity.getMagnitude() < .1) {
mySprite.animator.play('idle');
} else {
mySprite.animator.play('walking');
}
});Members
frames :Array.<Object>
The frames of the animation
- Array.<Object>
- Source
options :AnimationOptions
The animation's options
- Source
(static) propertyTypes
Animation types. Most types replace the value (absolute)
| Name | Type | Description |
|---|---|---|
simple | Apply the property by overwriting the old value each frame | |
object | Apply the property using Object.apply() each frame | |
number | A number | |
string | A string | |
boolean | A boolean | |
Image | A gameify.Image (on a sprite, or other object with a setImage method) | |
Vector2d | A gameify.Vector2d |
- Source
Methods
applyFrameTo(object, frame)
Apply an animation frame to an object
| Name | Type | Description |
|---|---|---|
object | Object | The object to apply the frame to |
frame | Object | The frame to apply |
- Source
applyTo(object, time)
Apply an animation frame to an object
| Name | Type | Description |
|---|---|---|
object | Object | The object to apply the frame to |
time | Number | The time (in milliseconds) to of the frame |
- Source
framesFromJSON(data, ref) → {Array.<AnimationFrame>}
Creates frames from their JSON representation
| Name | Type | Description |
|---|---|---|
data | Array | Serialized frame data (from object.framesToJSON) |
ref | function | A function that returns a name for other objects, so they can be restored |
- Source
- Type:
- Array.<AnimationFrame>
framesToJSON(keyopt, ref) → {Object}
Converts this animation's frames to JSON
| Name | Type | Attributes | Description |
|---|---|---|---|
key | string | <optional> | Key object is stored under (unused, here for consistency with e.g. Date.toJSON, etc.) |
ref | function | A function that returns a name for other objects, so they can be restored later |
- Source
- Type:
- Object
fromJSON(data, ref) → {gameify.Animation}
Creates a object from JSON data
| Name | Type | Description |
|---|---|---|
data | Object | | Serialized object data (from object.toJSON) |
ref | function | A function that returns a name for other objects, so they can be restored later |
- Source
- Type:
- gameify.
Animation
getFrameAt(time) → {Object}
Get the frame at the given time
| Name | Type | Description |
|---|---|---|
time | Number | The time (in milliseconds) to get the frame at |
- Source
- Type:
- Object
getFrameNumberAt(time) → {Number}
Get the frame number at the given time
| Name | Type | Description |
|---|---|---|
time | Number | The time (in milliseconds) to get the frame at |
- Source
- Type:
- Number
isAfterCompletion(time)
Check if a the animation is completed after a specific time If options.loop is true, always returns false
| Name | Type | Description |
|---|---|---|
time | Number | The time (in milliseconds) to check if the animation is completed at |
- Source
setFrames(frames)
Update the animation's frames
| Name | Type | Description |
|---|---|---|
frames | Array.<AnimationFrame> | The new frames |
- Source
toJSON(keyopt, ref) → {Object}
Convert the object to JSON
| Name | Type | Attributes | Description |
|---|---|---|---|
key | string | <optional> | Key object is stored under (unused, here for consistency with e.g. Date.toJSON, etc.) |
ref | function | A function that returns a name for other objects, so they can be restored later |
- Source
- Type:
- Object