1、功能
定义一个int属性,需要让它再哪个范围内改变自己的值,一般都是用定时器+随机来完成,但是这样的值不是连续的。用动画可完美实现这个功能。
2、代码
Rectangle { id: root 600 height: 400 property int speed: 0 SequentialAnimation { running: true loops: Animation.Infinite NumberAnimation { target: root; property: "speed"; to: 145; easing.type: Easing.InOutQuad; duration: 4000; } NumberAnimation { target: root; property: "speed"; to: 10; easing.type: Easing.InOutQuad; duration: 2000; } }
}
如代码:将speed从0连续非线性改变到145,再从145连续非线性改变到10.
通过这种方式,将值赋值给仪表盘,可以模拟车辆行驶过程~