Step 6 - Add application states

In this step you learn how to use the State Tools window to create and use application states.

Create states in the State Tools window

Use a State Manager to create different states in your Kanzi application.

The State Tools window shows the State Manager for the node you select in the Node Tree window.

You can find the State Tools window below the Preview window.

../../_images/car-create-state-manager.png

In this section you use the Kanzi Studio State Tools to create a state manager and define application states.

To create states in the State Tools window:

  1. In the Pages window click the Car node to go to that Page node.

    ../../_images/pages-car-page-step-6.png
  2. In the Node Tree window in the Car > Car Viewport 2D node select the CarScene node.

    ../../_images/project-car-node.png
  3. In the State Tools window click Create State Manager. Kanzi Studio creates a new state manager, assigns it to the CarScene node, and sets the State Tools window to the Edit mode. When the State Tools window is in the Edit mode, the Preview window tab and border turn orange.

    Tip

    When the State Tools window is in the Edit mode Kanzi Studio keeps track of all the changes you make to the property values in the selected node and its tree. If you are not changing the definition of states in your application, switch off the editing mode of the State Tools.

    ../../_images/car-create-state-manager.png
  4. In the State Tools click Create State twice to create two states, double-click the name of each state, and rename the states.

    For example, name one state Side and the other Front.

    ../../_images/state-tools-two-states-renamed.png
  5. Use the State Tools to set what the application looks like in that state:

    1. In the Node Tree window select the CarScene > RootNode > CameraRoot node and in the Properties window set the Render Transformation Rotation Y property field to 20.

      With this setting you show the car model from a different angle by rotating the node which contains the Camera node.

      ../../_images/project-car-camera_root.png ../../_images/properties-camera_root-rotation-y-side.png
    2. In the State Tools window in the Side state click image0.

      When you click image1 Kanzi Studio saves to that state the values of properties you changed in the project.

      ../../_images/state-tools-side-set.png
  6. Repeat the previous step, but set the Render Transformation Rotation Y property field to -20 and save the change to the Front state.

    ../../_images/properties-camera_root-rotation-y-front.png ../../_images/state-tools-front-set.png

    Tip

    When the State Tools window is in the Edit you can click any state in that State Manager to see what your application looks like in that state.

  7. Click Edit State Manager to exit the State Tools Edit mode.

    ../../_images/state-tools-off1.png

Set the application state

In this section you create a button in your Kanzi application which allows users of your application to switch between the states you created in the previous section.

To set the application state:

  1. In the Node Tree window press Alt and right-click the Car Page node and select Button 2D.

    ../../_images/car-create-button.png
  2. In the Properties window add the Horizontal Alignment and Vertical Alignment properties and set both to Stretch.

    With this setting you set the size of the Button 2D node to be of the same size as the Car Page node, its parent node. In this way you enable the users of your application to click anywhere in Car Page node to activate the button.

    ../../_images/button-alignment-stretch.png
  3. In the Node Components press Alt and right-click the Button: Click trigger, and select Dispatch Message Action > State Manager > Next State.

    Use the Next State action to go to the next state in the state group of the state manager you set in this action.

    ../../_images/triggers-add-next-state-action.png
  4. In the Next State action set:

    • State Group to StateGroup

    • Target Item to Prefabs/CarScene/CarScene

    ../../_images/next-state-action-settings.png

In the Preview window when you click anywhere in the Car Page, except the Next and Previous buttons, you switch between the Side and Front application states.

../../_images/getting-started-step-6.gif

< Previous step

Getting help

To open the Kanzi documentation in Kanzi Studio press F1.

Kanzi Studio opens Kanzi documentation in your default browser.

../../_images/kanzi-documentation.png

See also

To find out more about working with the state managers, see Using state managers.