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 小时前
qss/css 样式中margin和padding的作用和区别
css·qt
读书札记20221 天前
Qt界面卡死问题探讨及解决方法
qt
bug和崩溃我都要1 天前
Qt 封装 libmpv 全功能视频播放器开发指南
开发语言·qt·音视频
郝学胜-神的一滴1 天前
Qt 高级开发 018:复刻经典登录界面布局与窗口美化全解析
开发语言·c++·qt·程序人生·用户界面
小新1101 天前
qt creator 将qInfo的输出日志写入日志文档,方便查看
开发语言·qt
hssfscv1 天前
QT的学习记录1
开发语言·qt·学习
yong99901 天前
基于Qt的文件传输系统
开发语言·qt
誰能久伴不乏1 天前
ibmodbus “Invalid argument“ 错误的排查与修复
c++·qt·modbus
肥or胖1 天前
Qt中OpenGL快速入门
qt·音视频·opengl
程序员如山石2 天前
QT标签左侧水平显示
qt