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

相关推荐
Quz13 小时前
QML Label 完整用法与 Text 组件选型
前端·qt
kaixin_learn_qt_ing15 小时前
QPluginLoader
qt
kaixin_learn_qt_ing20 小时前
Qt 提升部件(Promote)找不到头文件路径
qt
秋田君2 天前
QT_QT布局详解
开发语言·数据库·qt
辞旧 lekkk2 天前
【Qt系统相关】鼠标事件
linux·开发语言·qt·学习·计算机外设·萌新
brave_zhao2 天前
什么是Qt Designer
开发语言·qt
贺国亚2 天前
A2A协议与Agent互操作-Task生命周期
开发语言·qt
luoyayun3612 天前
Qt + FFmpeg 视频工具:视频一键压缩功能实现
qt·ffmpeg·音视频·视频压缩
blueman88882 天前
Qt5通过vcpkg中调用时,在debug模式下调试时总是调用release的plugins文件夹中的dll
c++·qt·cmake
南国韭菜3 天前
【无标题】
c++·qt