Use the QT animation framework to design a two-dimensional animation for a role (2)
Connected
Logs.
Although the demo was last released using a large number of animation frameworks and Finite State Machine frameworks, it still has flaws. For example, when a user keeps pressing the key, the role will be frozen, but the position of the role is moving. This may be a side effect of using qkeyeventtransition. When I noticed that the use of qkeyeventtransition was poor, I began to look at how to save the QT key status and encapsulate it to make it easier for other encodings. For this reason, I wrote two logs. This log is a continuation of the previous key log and is also a specific application.
DemoProgram: Here
Source code: Here
Code It's a bit long. Let me talk about the Implementation ideas.
Here, we can move the early music up, down, and left, and you keep pressing the direction key will not cause her to be frozen. This is because I first saved the status of the QT key and abstracted it through the control Abstract class. In the window event loop, I updated all the elements in the scenario every 16 milliseconds through a qtimer, the directioncontrol subclass of the control is updated in the update () function of the primary speaker, and the update code of direconconrtrol contains the response to the buttons. The reason why we choose to update every 16 milliseconds is that the refresh time for each frame is only 1/60 = 0.0167 seconds for 60 frames per second. Here, we only need 0.016 seconds to remove the zero header, that is, 16 milliseconds.
Character, the parent class of the primary speaker, maintains a finite state machine and two states: standing and walking. The transition between the two States is different, just as in the previous article Article To switch from standing to walking, you must press the button without any animation at this time, but from walking to standing is a moment. That is, once the animation is completed, the animation is converted from walking to standing, and there is no animation at this time. The conversion from standing to walking status is described in detail here. I didn't use the qkeyeventtransition class, as shown in the previous article. Here I use another conversion: qsignaltransition. The principle is very simple. When we judge the keys and trigger conditions in direcontrol control, a signal from emit to qsignaltransition can successfully trigger the transition from standing to walking.
It sounds a bit false. It seems that you still need to understand it through code. If you want to learn more, you can download and run the source code of the program. My development environment is:
Windows: WindowsXP (SP3) + mingw4.4/mingw4.7 + qt4.8.3/qt5.0.1 + qtcreator2.6/qtcreator2.7
Linux: ubuntu12.10 + gcc4.7 + qt4.8.1/qt4.8.4/qt5.0.1 + qtcreator2.6/qtcreator2.7