Skip to content

JSON configuration

Whitebrim edited this page Jun 6, 2022 · 6 revisions

You can store states in JSON file in the project (example_2A).

JSON file structure

[
    {
        "name": "default",
        "tickStep": 3
    },
    {
        "name":"idle",
        "firstFrameIndex": 1,
        "framesCount": 20,
        "animationStartingFrame": 1,
        "tickStep": 1,
        "frameStep": 1,
        "reverse": false,
        "loop": true,
        "yoyo": false,
        "flip": 0,
        "xScale": 1,
        "yScale": 1,
        "frames":[1, 2, 3, 7, 8, 13, 14, 15],
        "nextAnimation": "OptionalSecondState"
    },
    {
        "name":"OptionalSecondState",
        "tickStep": 3
    },
]

Changing the default state is optional: It contains default values for all states.
Values from default state will be used if they're not overwritten in a state.
For example, if all your states need tickStep to be 3, you can just set states.default.tickStep to 3 before adding states or change default state in json config as shown above.
All values are optional besides "name". If the value is not overwritten, the state will be assigned with the value from the default state.

The only difference between json load and :addState(...) is that
json state is configured with first frame index and frames COUNT, but
in :addState(...) function first frame index and last frame INDEX are used.

You can't assign function for events in json, you need to change them manually, see example_3B.

Clone this wiki locally