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

相关推荐
精英的英3 小时前
记一次 Qt5 Language Server 开发
开发语言·vscode·qt
不会代码的小猴8 小时前
4. 控件学习2
开发语言·c++·笔记·qt
我是小灰灰吖9 小时前
解决高频率图像处理中的内存“只增不减”:glibc malloc_trim实战指南
linux·qt
秋田君10 小时前
QT_一个UDP通信程序(单播+广播)
开发语言·qt·udp
我是小灰灰吖10 小时前
Qt 6.9.3 Ubuntu 22.04 虚拟键盘显示问题全记录与解决方案
linux·qt·ubuntu
C++ 老炮儿的技术栈1 天前
Qt5.9.1 Windows 完整开发环境搭建流程
开发语言·c++·windows·qt·编辑器·代码化
Quz1 天前
QML ComboBox 可编辑输入与动态更新模型
qt
丰锋ff1 天前
7.2Qt中Json的操作
开发语言·qt·json
我不是疯子是傻子1 天前
用DeepSeek生成Qt多协议解析器?「正则+状态机+AI分支裁剪」混合调优实战
开发语言·qt
qq_401700411 天前
QT段错误一般是什么原因造成的,如何快速排查
qt