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

相关推荐
小灰灰搞电子3 小时前
Qt 开发环境选择Qt Creator、Visual Studio还是 VS Code?
开发语言·qt·visual studio
淼淼7636 小时前
Qt调度 程序
开发语言·c++·windows·qt
明飞19876 小时前
QT笔记1
qt
林政硕(Cohen0415)6 小时前
ARM Qt 字体过小的问题
arm开发·qt
追烽少年x7 小时前
Qt中构建多语言程序
qt
rainFFrain8 小时前
QT显示类控件---QSlider
开发语言·qt
扶尔魔ocy13 小时前
【QT window】multimedia+ffmpeg实现(PCM和MP4)录音功能
qt·ffmpeg·pcm
YouEmbedded14 小时前
解码 Qt 交互:滑动交互、窗口拖拽
qt·滑动交互·上滑关闭·滑动显示 / 隐藏
郝学胜-神的一滴14 小时前
使用EBO绘制图形:解锁高效渲染与内存节省之道
c++·qt·游戏·设计模式·系统架构·图形渲染