kanzi: how to use state machines (1)

Today, let's talk about the state machine in kanzi.

But how to create and how to use it has already been said in detail in the doc, so I won't say nonsense. Today I mainly talk about the places that should be paid attention to when encountering it.


1. The state machine can meet many of our UI needs. Now let's talk about a simple sequence frame. For example, the wifi signal, the signal flashes when connecting.

Similar to this simple animation, if we use animation, we also need to control the start and end of the animation in the program, but if we use a state machine to achieve it, it is much simpler, and at most we can set the properties.

First, we record the state like a general state machine, and then, give a variable, after recording these states, we will realize this animation effect. Then add this property to this node.


Add an action to the node trigger of our recording state: onproperty change, which means that one thing changes another thing. The addition is complete, ok, it's time to implement this animation effect.

It's actually simple to come down, click on the action you just added, and follow the prompts to add the premise first, if a certain attribute is, or a certain message. It is relatively simple here. When the state of our node is equal to a certain value, then we add the preconditions and play, and then we add an action, which means that this attribute changes, then we need to modify a certain attribute. We add a setproperty and set the next state. Note that there is a delay in the back. For the animation effect, we set 1000ms to change every 1s. In this way, after adding all the states in sequence, it will form a similar cycle. For example: the signal goes from 0 to 1, from 1 to 2, from 2 to 3, from 3 to 4, from 4 to 0.

If this step is ok, then this is done.


Let's try changing the variable added by this node.


2. What if we add a state machine to a button, but there is a similar button that also uses the state machine, it is actually very simple, add a property state manager to this button, and then add the required state machine Just come in. And these two state machines are actually similar to our object types (for example: int), and your two buttons are similar to objects, variables, and actually do not interfere with each other. So you set the state of one does not affect the other.


3. We can also implement simple animation effects in the state machine. I won't talk about the operation here. You only need to add the transitions action. This thing knows how to use it after reading it, so I won't say much. But I mainly say one point now, if your state machine is in one of your root nodes (for example, you use it in a template), then you may find that there is no animation effect when you finish this work, and it does not achieve the effect you expected. Then don't worry, don't do a lot, create a node under your root node, add the animation effect to this node (if it has been recorded, add the state manager directly), then try it and find that it has, so this animation effect is the best Well, don't use it on the root node.


4. In fact, kanzi also helped us with the variable attributes of the state machine. For example, when you click the button, you don't need to create the attribute yourself, and then set the attribute value. It is easier to directly use the isdown attribute of the button.


5. In transitions, if you actually set it yourself, click the icon on the right, and you can set it as you want, and add it as you want.


That's all I can think of right now. It's easy for everyone to know, so I won't say too much. I'll write it later when I encounter something that needs attention.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325550035&siteId=291194637