States

States are sets of layer properties and values. You can add, remove or switch between states. State switching can be done with or without an animation, and you can define different animation options for individual states too.

layer.states.add(name <string>, state <object> | states <object>)

Adds a layer state. Each layer state is a collection of layer properties and values. You can add them one by one with a name and property object or all at once with an object containing the layer names and properties. There is always a "default" state, containing the property values that the layer was created with. 레이어 상태를 추가한다. 각 레이어의 상태는 레이어 속성과 값의 집합이다. 여러분은 이름과 속성 객체를 하나씩 추가할 수도 있고, 레이어의 이름과 속성들을 포함하는 객체를 한번에 추가할 수도 있다.
이는 언제나 "default" 상태로, 생성된 레이어의 속성값을 포함한다.

layerA = new Layer

# Add a single state
layerA.states.add
   stateA:
       x: 500
       opacity: 0.5

# Add a multiple states
layerA.states.add
   stateA:
       x: 500
       opacity: 0.5

   stateB:
       x: 200
       opacity: 1

layer.states.remove(name <string>)

Remove a layer state by name.
레이어 상태를 이름으로 찾아 삭제한다.

layerA = new Layer

layerA.states.add
   stateA:
       x: 500
       opacity: 0.5

layerA.states.remove("stateA")

layer.states.switch(name <string>)

Switch to a new state. This will animate the layer to the new state. By default, it will use the layer.states.animationOptions.
새로운 상태로 전환. 해당 레이어에 새로운 상태로 애니메이션 효과를 준다. 기본값으로 layer.states.animationOptions 를 사용한다.

layerA = new Layer

layerA.states.add
   stateA:
       x: 500
       opacity: 0.5

layerA.states.switch("stateA")

layer.states.switchInstant(name <string>)

Switch to a new state without animating.
애니메이션 효과 없이 새로운 상태로 전환한다.

layerA = new Layer

layerA.states.add
   stateA:
       x: 500
       opacity: 0.5

layerA.states.switchInstant("stateA")

layer.states.current <string>

The name of the current state.
현재 상태의 이름.

layerA = new Layer

layerA.states.add
   stateA:
       x: 500
       opacity: 0.5

layerA.states.switchInstant("stateA")

print layerA.states.current
# 출력: stateA

layer.states.next(states <array>)

Switches to the next state. If we reach the end of the states we start at the beginning again. You can provide an array of state names for the ordering. If you don't provide an array with state names it will use the ordering by when a state got added.
레이어를 다음 상태로 전환한다. 만약 주어진 상태의 마지막까지 다다랐다면, 맨 처음부터 다시 상태값을 실행한다. 여러분은 상태의 이름을 원하는 순서대로 array로 만들 수 있다. 만약 여러분이 array를 상태의 이름으로 제공하지 않으면, 상태값이 추가된 순서대로 실행된다.

layerA = new Layer

layerA.states.add
    stateA:
        x: 500
        opacity: 0.5

    stateB:
        x: 200
        opacity: 1

# Every time we call this we cycle through the states  
layerA.states.next("stateA", "stateB")

layer.states.animationOptions <object>

Set the animation options for the state machine. By default, the global animation options will be used.
state machine에 따라 애니메이션 옵션을 설정한다. 기본값으론 글로벌 애니메이션 옵션이 사용된다.

layerA = new Layer

layerA.states.add
    stateA:
        x: 500
        opacity: 0.5

    stateB:
        x: 200
        opacity: 1

layerA.states.animationOptions =
    curve: "spring(100, 10, 0)"

layerA.states.switch("stateA")

These animation options will now be used for all state switches. To set different animation options for individual states, you can include them directly within the switch statement.
이러한 애니메이션 옵션은 모든 상태를 변경하는데 사용된다. 각각의 상태들을 다른 애니메이션 옵션으로 설정하고자 한다면, 상태들에 변경할 상태값을 직접 포함시킬 수 있다.

# Switch to stateB with a spring curve  
# stateB를 spring curve로 변경
layerA.states.switch("stateB", curve: "spring(400, 30, 0)")

# Switch to stateB with an easing curve  
# stateB를 easing curve로 변경
layerA.states.switch("stateB", time: 1, curve: "ease")