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

相关推荐
Jun62611 小时前
QT(3)-线程中使用控件
开发语言·qt
Jun62611 小时前
QT(1)-C/C++库生成和调用
c语言·开发语言·c++·qt
Jun62611 小时前
QT(10)-TCP数据收发
开发语言·qt·tcp/ip
Littlehero_12111 小时前
QT自定义控件之热换站远程监控系统
c++·qt
努力努力再努力wz11 小时前
【Qt入门系列】一文掌握 Qt 常用显示类控件:QLCDNumber、QProgressBar 与 QCalendarWidget
c语言·开发语言·数据结构·数据库·c++·git·qt
C++ 老炮儿的技术栈12 小时前
如何利用 OpenCV 将图像显示在对话框窗口上
c语言·c++·人工智能·qt·opencv·计算机视觉·github
ALINX技术博客13 小时前
【黑金云课堂】FPGA技术教程Linux开发:NVMe/Qt/OpenCV人脸检测
linux·qt·fpga开发
Jun62614 小时前
QT(4)-EXCEL操作
开发语言·qt·excel
郝学胜-神的一滴15 小时前
Qt 高级开发 025:打造优雅界面的艺术与高效重构之道
开发语言·c++·qt·程序人生·重构·软件构建·用户界面
Vertira16 小时前
VS2022 配置Qt5/6 [已解决]
开发语言·qt