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

相关推荐
imatt17 小时前
Qt Creator 在Windows下编译信息乱码
windows·qt
赤水无泪17 小时前
qt中图标、名称的设置方式
开发语言·qt
房开民21 小时前
Qt TCP 服务器开发实战:与 VisionMaster OCR 通信
服务器·qt·tcp/ip
熬夜苦读学习1 天前
QT_信号和槽
开发语言·qt
Quz1 天前
QML 文字入场动画:逐字弹出、逐字飞入、3D 飞入
qt·3d·动画·qml
豆浆D油条2 天前
QT容器类QList调用erase崩溃
开发语言·qt·rpc
杜子不疼.2 天前
【Qt常用控件】WindowTitle 与 WindowIcon:窗口标题和图标
开发语言·qt
sycmancia3 天前
Qt——另一种创建线程的方式
开发语言·qt
sycmancia3 天前
Qt——多线程与界面组件的通信
开发语言·qt·算法
Quz3 天前
QML 基础组件专栏目录(V1)
qt·qml