States » Creating states

Creating states

This is our example layer, a red square:

redSquare = new Layer
    size: 300
    backgroundColor: "red"

Each layer has a states object in which you save those states.

To add a state, you select a name (anything except ‘default,’ obviously) and set the desired properties.

Let’s pick "bigAndBlue":

redSquare.states.bigAndBlue =
    scale: 2
    backgroundColor: "blue"

The redSquare layer has now, next to its default state, one new state: "bigAndBlue".

You can also define several states at the same time if you want, like this:

redSquare.states =
        scale: .5
        backgroundColor: "orange"
        rotation: 45

But keep in mind that when using layer.states =, you’ll override any states that may have been set previously.

In this example, "bigAndBlue" doesn’t exist anymore, and the layer now has three states: "smallAndOrange", "rotated" and, as always, "default".