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

相关推荐
茯苓gao20 小时前
嵌入式开发笔记:QSerialPort 完整使用指南——从基础 API 到工程实战
笔记·嵌入式硬件·qt·学习
丁劲犇1 天前
AI辅助快速实现动态多载波PSK随机信号源
人工智能·qt·ai·sdr·多相滤波·动态生成
Quz1 天前
QML Slider 组件:基础滑块、自定义手柄、刻度标记与自定义轨道
qt
dok121 天前
zynq qt 交叉编译
开发语言·qt
龚建波2 天前
《QDebug 2026年6月》
qt
△曉風殘月〆2 天前
如何在Linux中安装Qt开发环境
linux·运维·qt
Quz2 天前
QML 选择控件:Switch、CheckBox 与 RadioButton
qt
熬夜苦读学习2 天前
Qt常用控件
服务器·开发语言·qt
夏玉林的学习之路2 天前
Qt 项目编译错误排查与解决记录
开发语言·qt
Quz3 天前
QML 基础按钮:Button、RoundButton 与 DelayButton
qt