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---21(QT中QFile库的QFile读取文件、写入文件的讲解)
c++·qt·学习
醇醛酸醚酮酯4 小时前
Qt项目锻炼——TODO(五)
开发语言·qt
沙振宇10 小时前
【Qt 学习之路】Qt Android开发环境搭建:Ubuntu的Vmware虚拟机中的踩坑实录
android·qt·学习
鸥梨菌Honevid10 小时前
QT解析文本框数据——概述
数据库·qt·mysql
给自己记录用11 小时前
qt笔记(1)——Qtablewidget使用
笔记·qt
AI+程序员在路上14 小时前
Qt6中模态与非模态对话框区别
开发语言·c++·qt
哈市雪花21 小时前
相机:以鼠标点为中心缩放(使用OpenGL+QT开发三维CAD)
qt·相机·opengl·cad·缩放·工业软件·渲染效果
Tony小周1 天前
实现一个点击输入框可以弹出的数字软键盘控件 qt 5.12
开发语言·数据库·qt
雨落倾城夏未凉1 天前
8.Qt文件操作
c++·后端·qt
TechNomad1 天前
Qt开发:QtConcurrent介绍和使用
qt