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

相关推荐
小温冲冲11 小时前
QtObject 详解:QML 中的轻量级数据容器
qt
huwei85312 小时前
Q打印表格内容类
开发语言·qt
Quz16 小时前
QML 常用的基础容器组件(Pane、Frame、GroupBox、ScrollView 和 Page)
qt·交互
墨月白16 小时前
[QT] QT中的折线图和散点图
数据库·qt
问水っ17 小时前
Qt Creator快速入门 第三版 第16-7章 其他内容
开发语言·qt
Tianwen_Burning18 小时前
qt控件QVTKOpenGLNativeWidget全窗口显示
qt·pcl·halcon3d
小CC吃豆子19 小时前
Qt的信号与槽机制
开发语言·数据库·qt
qq_4017004119 小时前
Qt属性系统
开发语言·数据库·qt
默默前行的虫虫20 小时前
QT、html中的大屏可视化带源码
qt
郝学胜-神的一滴20 小时前
Qt实现圆角窗口的两种方案详解
开发语言·c++·qt·程序人生