足球移动动画

来源:互联网 发布:手机淘宝怎样撤销投诉 编辑:程序博客网 时间:2024/04/30 19:46
import QtQuick 2.6
import QtQuick.Controls 1.5
ApplicationWindow {
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")
    menuBar: MenuBar {
        Menu {
            title: qsTr("File")
            MenuItem {
                text: qsTr("&Open")
                onTriggered: console.log("Open action triggered");
            }
            MenuItem {
                text: qsTr("Exit")
                onTriggered: Qt.quit();
            }
        }
    }
    property int duration: 3000
    Rectangle {
            id: sky
            width: parent.width
            height: parent.height/2
            gradient: Gradient {
                GradientStop { position: 0.0; color: "#0080FF" }
                GradientStop { position: 1.0; color: "#66CCFF" }
            }
        }
    Rectangle {
        id: ground
        anchors.top: sky.bottom
        //height: 200
        anchors.bottom: parent.bottom
        width: parent.width
        gradient: Gradient {
            GradientStop { position: 0.0; color: "#00FF00" }
            GradientStop { position: 1.0; color: "#00803F" }
        }
    }
    Image {
        id: football
        source: "test2.png"
        x:10
        y:parent.height-100
        width: 40
        height: 40
        //anchors.bottom: ground.bottom
        MouseArea{
            anchors.fill: parent
            onClicked: {
                football.x=10
                football.y = football.parent.height-football.height
                football.rotation = 0
                anim.restart()
            }
        }
    }
    SequentialAnimation {
        id: anim
        NumberAnimation {
            target: football
            properties: "x,y"
            to: 150
            duration: parent.duration * 4
        }
        NumberAnimation {
            target: football
            properties: "x,y"
            to: 0
            duration: parent.duration * 14
        }
        NumberAnimation {
            target: football
            properties: "x,y"
            to: anim.parent.height
            duration: parent.duration * 16
        }
    }
}
                                             
0 0