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

 

相关推荐
扶尔魔ocy1 天前
【QT入门到晋级】用开源的自定义控件开发
c++·qt·自定义控件
lhbweilai1 天前
QT项目(串口助手)
开发语言·qt
小鱼仙官2 天前
Qt 主界面弹出分界面
开发语言·qt
誰能久伴不乏2 天前
用 UDP 做一条“可靠“的控制通道
c++·qt·网络协议·udp
Bczheng12 天前
VS2022 安装MFC和QT
c++·qt·mfc
会编程的小孩2 天前
8.19号函数
qt
蓝祁子yoky3 天前
Qt学习日记 Day15:网络编程(二)- UDP基础
网络·qt·学习
读书札记20223 天前
Qt UTF-8和UTF-8(BOM)
开发语言·qt
ShineWinsu3 天前
对于Qt:QProgressBar常见属性的解析
开发语言·c++·qt·进度条·gui·定时器·qprogressbar
ShineWinsu3 天前
对于Qt:QLCDNumber常见属性以及QTimer的解析
服务器·数据库·c++·qt·gui·qtimer·qlcdnumber