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

相关推荐
苕皮蓝牙土豆5 小时前
Qt图形视图框架入门:坐标系统与鼠标事件处理详解
c++·qt
纤纡.6 小时前
基于 PyQt5 的桌面应用开发实战:登录、预测、计算器、摄像头多功能系统
开发语言·人工智能·qt·计算机视觉
Fleshy数模8 小时前
PyQt5 登录界面开发全流程:从环境配置到可视化设计
开发语言·python·qt
用户8055336980310 小时前
现代Qt开发教程(新手篇)1.6——内存管理
c++·qt
m0_5027249511 小时前
qt键盘钩子完善
stm32·qt·计算机外设
广州灵眸科技有限公司11 小时前
瑞芯微(EASY EAI)RV1126B QT GUI例程方案
linux·服务器·开发语言·网络·人工智能·qt·物联网
xcjbqd011 小时前
Qt Quick中QML与C++交互详解及场景切换实现
c++·qt·交互
小樱花的樱花12 小时前
5 实现文件打开功能
开发语言·数据库·c++·qt·ui
Drone_xjw1 天前
一次 Qt 程序在 Kylin 系统下表头“白屏”的排查之旅
qt·kylin·一次
尘中远1 天前
Qwt 7.0 新特性介绍 — 更现代、更强大的Qt数据可视化库
qt·qwt·科学绘图·曲线图