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

相关推荐
Quz2 小时前
QML Tumbler 样式定制:渐变、高亮与 3D 滚轮效果
qt
隐积14 小时前
3.1.7.Qt容器大家族(3):QVariant——万能盒子
开发语言·qt
熬夜苦读学习1 天前
Qt-- 系统相关
开发语言·qt
Quz1 天前
QML Tumbler 基础用法:多滚轮选择与自定义外观
qt
Quz1 天前
QML SpinBox 动画效果:缩放反馈与数字滚动
qt
小灰灰搞电子2 天前
Qt 实现魔法导航菜单源码分享
开发语言·qt
Quz2 天前
QML SpinBox 基础与步长控制:可编辑输入与自定义步长
qt
隐积2 天前
Qt魔法之旅 · 全系列课程导航
qt
海清河晏1112 天前
Qt 实战:信号与槽+事件系统
开发语言·c++·qt
郝学胜-神的一滴2 天前
Qt 高级编程 037:QSS按钮样式封神指南
开发语言·c++·qt·软件工程·用户界面