Skip to content

Config parameters

Whitebrim edited this page Mar 9, 2023 · 9 revisions

name (string)

Name of the state, should be unique, used as id.


firstFrameIndex (integer or string) [optional]

Index of the first frame in the imagetable. Indexing starts from 1!
If initialised with string (name of the state), firstFrameIndex will be the next frame after the last frame from that state.
In this case if there are any changes in the imagetable structure, then only the framesCount field of the changed states need to be updated in the json config.


framesCount (integer) [optional]

How many total frames of animation there are in this animation state. The animation will start with
the frame number specified by firstFrameIndex, and include [framesCount] frames in the animation.
If not provided, this state will have all frames till the end of the imagetable.


animationStartingFrame (integer) [optional]

Local index of the frame to start animation with. First frame of the state (firstFrameIndex frame) will be indexed as 1.
The only one parameter that doesn't use default state value when assigned!
If not provided, will be 1 if reverse is false, else will be the last frame.


reverse (boolean) [optional]

Default value is false.
If true then animation will be animated backwards.
If reverse = true, then it's highly recommended to leave animationStartingFrame blank,
so the system can assign the last frame index by itself.


loop (boolean or integer) [optional]

Default value is true, false if nextAnimation is provided.
If true, animation will loop endlessly from the last frame to the first
If false, animation will call :stopAnimation() function on the last frame
If initialised with integer, animation will call :stopAnimation() function after provided amount of finished loops.
Initialising with false and 1 gives the same effect.


yoyo (boolean) [optional]

Default value is false.
If true, the animation will be played in ping-pong style: 1-2-3-2-1-2-3-2-1.
Finished loops are counted the same way when 'yoyo' is set to true.
For example an animation with 4 frames, set to loop 2 times would animate 1-2-3-4-3-2-1 before calling :stopAnimation().


tickStep (number) [optional]

Default value is 1.
Speed of the animation, larger value -> slower animation.
Amount of frames (fps) between changing sprites.
1 = update every frame.


frameStep (integer) [optional]

Default value is 1.
Amount of frames to skip between animation updates.
If you want to draw only every second image from your imagetable, set frameStep to 2.


flip (0 or 1 or 2 or 3) [optional]

Default value is 0 (unflipped).
Flips images to draw along the axes.
0 = playdate.geometry.kUnflipped
1 = playdate.geometry.kFlippedX
2 = playdate.geometry.kFlippedY
3 = playdate.geometry.kFlippedXY


xScale, yScale (number) [optional]

Default value is 1.
Scale for horizontal, vertical axis.


nextAnimation (string) [optional]

Default value is nil.
Name of the existing animation state to switch to automatically after this animation ends.
If nextAnimation is set and loop is not set, then loop will be set to false by default.
If nextAnimation is not provided and loop is not endless then after animation ends :stopAnimation() will be called.


frames (table of integers) [optional]

If you provide the table with indexes then the animation will draw frames of these indexes.
Useful for cases when you need to build a state with frames that are not sequential.
If set, firstFrameIndex, framesCount, [startFrame] and [endFrame] arguments of :addState function will do nothing.



Events

See example_3B.
All events receive an AnimatedSprite instance (self) as first argument.


onFrameChangedEvent(self)

The event that will be triggered when the animation transitions to the next frame.
Guaranteed to be called before onLoopFinishedEvent.


onLoopFinishedEvent(self)

The event that will be triggered every time when the animation enters the loop's last frame.
Guaranteed to be called after onFrameChangedEvent.


onAnimationEndEvent(self)

The event that will be raised when this animation state is over.
If this animation has nextAnimation set, next will be called onStateChangedEvent event from the next animation.
Guaranteed to be called after onLoopFinishedEvent.


onStateChangedEvent(self)

The event that will be triggered after the animation state changes. It indicates that this state is about to start playing. Called before the first onFrameChanged event.
Guaranteed to be called after onAnimationEndEvent.