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

相关推荐
啊森要自信17 分钟前
【QT】常⽤控件详解(六)多元素控件 QListWidget && Table Widget && Tree Widget
c语言·开发语言·c++·qt
ZPC821017 小时前
参数服务器 server and client
服务器·qt
牵牛老人18 小时前
Qt中的QWebSocket 和 QWebSocketServer详解:从协议说明到实际应用解析
开发语言·qt·网络协议
残醉2 天前
QT的拖拽功能
qt
蒋星熠2 天前
QT项目 -仿QQ音乐的音乐播放器(第五节)
开发语言·qt
冬停2 天前
解决 Qt 网络 SSL 报错:`cannot call unresolved function` 的终极指南
网络·qt·ssl
mct1233 天前
QUdpSocket发送组播和接受组播数据
qt·组播
火山上的企鹅3 天前
Qt Quick 之动态旋转刻度盘(无人机中指南针 Demo )
qt·无人机·cocos2d
是小峰呀3 天前
QT+opencv+yolov8推理
开发语言·qt·yolo
GUIQU.3 天前
【QT】概述
开发语言·c++·qt