Unsolved Animations in a state (QuickUltralite)
-
Hi everyone,
I've been struggling the past 3 days to find a solution for this.
In QuickUltralite, I managed to prototype a 2D character made up of 2D body parts I found on the web with some bone animations. Because transformations do not carry through to children, I had to get creative, but I got there.
Now all this movement is done with NumberAnimations, and I can work with that.
Image { id: upperArm source: "qrc:/resources/dragon_upper_arm.png" property real rot; NumberAnimation on rot { running: true loops: Animation.Infinite duration: 2000 from: 0 to: 2.0 * Math.PI } property matrix4x4 mat0 : translate(20, 20) property matrix4x4 mat1 : translate(42, 18) property matrix4x4 mat2 : rotatez(-rot) property matrix4x4 mat3 : translate(-42, -18) property matrix4x4 matf : torso.matf.times(mat0.times(mat1.times(mat2.times(mat3)))) transform: Matrix4x4 { matrix: upperArm.matf } }
But here's my challenge.
I want to create "states" for my character. States like "idle", "waving", "angry", "shouting", "talking", "walking", etc. Now the mechanisms for states are there, and even transition animations between states are there. But it seems to be impossible to create any kind of animation while the character stays within a state. I might want my "talking" state to be as long as 3 minutes, if that's how long the dialog is. But within those 3 minutes, there should be an animation looping. But states seem to always be entirely static.
I tried to define States within the top item of the character. I can define a lot of it. But I can't define the animation within the state it belongs in it seems. The animations types are not allowed to live in State or PropertyChanged.
states: [ State { name: "idle" when: dragonState === Dragon.DragonState.Idle // NOT ALLOWED // property real n; // NumberAnimation on n { // running: true // loops: Animation.Infinite // duration: 7500 // from: 0 // to: 2.0 * Math.PI // } // // property matrix4x4 mat0 : translate(-40 + (Math.sin(n) * 1.0), -120 + (Math.cos(n) * 4.0)) // property matrix4x4 matf : legFront.matf.times(mat0) PropertyChanges { target: upperArm // transform: Matrix4x4 { matrix: matf } } }, State { name: "waving" extend: "idle" when: dragonState === Dragon.DragonState.Waving PropertyChanges { target: upperArm // NOT ALLOWED EITHER // property real n; // NumberAnimation on n { // running: true // loops: Animation.Infinite // duration: 7500 // from: 0 // to: 2.0 * Math.PI // } // property matrix4x4 mat0 : translate(-40 + (Math.sin(n) * 1.0), -120 + (Math.cos(n) * 4.0)) // property matrix4x4 matf : legFront.matf.times(mat0) // transform: Matrix4x4 { matrix: matf } } } ]
Now. I may be able to solve this by defining states in every Image. But that is the wrong kind of encapsulation in my mind. The logic of waving animations, should be located in the same place, not spread across many different images. It can't seem to be done in QML though. Or am I missing something?
-
@reneb86 said in Animations in a state (QuickUltralite):
I want to create "states" for my character. States like "idle", "waving", "angry", "shouting", "talking", "walking", etc. Now the mechanisms for states are there, and even transition animations between states are there. But it seems to be impossible to create any kind of animation while the character stays within a state. I might want my "talking" state to be as long as 3 minutes, if that's how long the dialog is. But within those 3 minutes, there should be an animation looping. But states seem to always be entirely static.
I tried to define States within the top item of the character. I can define a lot of it. But I can't define the animation within the state it belongs in it seems. The animations types are not allowed to live in State or PropertyChanged.
Now. I may be able to solve this by defining states in every Image. But that is the wrong kind of encapsulation in my mind. The logic of waving animations, should be located in the same place, not spread across many different images. It can't seem to be done in QML though. Or am I missing something?My inclination is to:
- Define the animations outside of the states definitions, but adjacent in the QML file.
- Use a PropertyChanges or StateChangeScript to set the Animation's state to running and adjust loops if appropriate.