QML —— 顺序动画,足球落地示例(附完整源码)

效果

源码
cpp 复制代码
import QtQuick 2.12
import QtQuick.Window 2.12

Window
{
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")

    MouseArea
    {
        anchors.fill: parent
        onClicked:{setSequentialAnimationState(true)}
    }

    Component.onCompleted:{setSequentialAnimationState(false)}
    Component.onDestruction:{setSequentialAnimationState(false)}

    function setSequentialAnimationState(b)
    {
        if(b)
        {
            if(!sequentialAnimation.running){sequentialAnimation.start()}
        }
        else
        {
             if(sequentialAnimation.running){sequentialAnimation.stop()}
        }
    }

    Image
    {
        id: ballImg
        source: "ball.jpeg"
        scale: 0.3
        y: -height
        anchors.horizontalCenter: parent.horizontalCenter

        SequentialAnimation on y
        {
            id: sequentialAnimation
            loops: Animation.Infinite
            NumberAnimation
            {
                id: fallNumberAnimation
                to: ballImg.parent.height - ballImg.height
                easing.type: Easing.OutBounce
                duration: 2000
            }

            PauseAnimation {duration: 1000}

            NumberAnimation
            {
                to: -ballImg.height
                easing.type: Easing.OutQuad
                duration: 500
            }

        }
    }
}

关注

笔者 - jxd

相关推荐
机器视觉知识推荐、就业指导2 小时前
拆 Qt,为什么要先引入libmodbus?
开发语言·qt
载数而行5205 小时前
Qt中的信号和槽
qt
寒鸦飞尽5 小时前
QT中自定义标题栏
qt
Aaron_dw9 小时前
QT软件开发设计模式-模板方法模式
qt·设计模式·模板方法模式
Aaron_dw9 小时前
QT软件开发设计模式-观察者模式
qt·观察者模式·设计模式
小温冲冲9 小时前
ReSharper 在 Visual Studio 中的详细配置指南
c++·ide·qt·visual studio
爱搞事的程小猿9 小时前
qt系统字体方案
c++·qt
C++ 老炮儿的技术栈10 小时前
C++、C#常用语法对比
c语言·开发语言·c++·qt·c#·visual studio
Ronin30510 小时前
【Qt常用控件】多元素控件
开发语言·qt·常用控件·多元素控件
※※冰馨※※10 小时前
【QT】System error #1455: 页面文件太小,无法完成操作
开发语言·windows·qt