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

相关推荐
老赵的博客2 小时前
c++ QT之动态库加载问题
c++·qt
Quz6 小时前
QML Loader:动态创建控件与延迟加载
qt
Quz7 小时前
QML Loader:组件切换与属性传递
qt
老赵的博客7 小时前
c++QT之动态库加载常见报错
c++·qt
Quz1 天前
QML Loader:从文件加载组件、加载内联组件
qt
Quz1 天前
QML Loader: 状态监听与动态标签页
qt
似水এ᭄往昔1 天前
【Qt】--常用控件(显示类控件)
开发语言·qt
慧都小项1 天前
从 Figma 到 Qt:Qtitan 能减少哪些界面还原工作?
前端·qt·嵌入式·figma·图形界面·工业界面·qtitan
用户122003879001 天前
Qt学习之绘图入门练习
qt
西西弗Sisyphus1 天前
Qt 实现一个 Windows 启动项查看器
开发语言·windows·qt