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

相关推荐
「QT(C++)开发工程师」11 小时前
VTK开源视觉库 | 行业应用第一篇
linux·qt·物联网·计算机视觉·信息可视化·vtk
weixin_4672092814 小时前
Qt Creator打开项目提示no valid settings file could be found
开发语言·qt
合作小小程序员小小店15 小时前
舆情,情感微博系统demo,基于python+qt+nlp,开发语言python,界面库qt,无数据库版,数据来自第三方网站获取,
开发语言·pytorch·qt·自然语言处理·nlp
Larry_Yanan16 小时前
QML学习笔记(四十八)QML与C++交互:QML中可实例化C++对象
c++·笔记·qt·学习·ui·交互
伐尘20 小时前
【Qt】实现单例程序,禁止程序多开的几种方式
qt
2501_938780281 天前
《轨道交通检测系统中 Qt 与数据库交互的优化方案》
数据库·qt·交互
非得登录才能看吗?1 天前
Qt 外观之Qt样式表(QSS)
qt
LNN20221 天前
Qt creator +Valgrind检测内存泄漏(linux)
linux·开发语言·qt
奔跑吧 android1 天前
【Docker】【03.使用docker搭建ubuntu20.04 Qt5.12 开发环境】
qt·docker·ubuntu20.04·qt5.12
扶尔魔ocy2 天前
【QT常用技术讲解】可拖拽文件的Widget--QListWidget
开发语言·qt