2016-10-04 18 views
1

オブジェクトが必要です。複雑なパスに仲間入りしてアニメーションとして移動する必要があります。 パスはラインとカーブに含まれています。電車のように。QMLアニメーションを反転させる方法

二溶液:1のマルチアニメーション

問題1. PathAnimationまたは2 states: 電車多分(アニメーションを一時停止)、ランダムな時点で停止し、バックには逆に行きます開始位置(アニメーションを逆に再生)。

だから私は逆にPathAnimationを再生する方法を知りたいですか?

答えて

0

QMLにはその機能がないと思います。

新しいパスが必要なときは、いつでも新しいパスを設定できます。私は、あなたがアニメーションが終了するとき。

ここでは、例を持っている:

import QtQuick 2.3 
import QtQuick.Controls 1.1 

ApplicationWindow { 
    visible: true 
    width: 350 
    height: 300 

    Rectangle { 
     id: window 
     width: 350 
     height: 300 

     Canvas { 
      id: canvas 
      anchors.fill: parent 
      antialiasing: true 

      onPaint: { 
       var context = canvas.getContext("2d") 
       context.clearRect(0, 0, width, height) 
       context.strokeStyle = "black" 
       context.path = pathAnim.path 
       context.stroke() 
      } 
     } 

     SequentialAnimation { 
      id: mySeqAnim 
      running: true 

      PauseAnimation { duration: 1000 } 

      PathAnimation { 
       id: pathAnim 

       duration: 2000 
       easing.type: Easing.InQuad 

       target: box 
       orientation: PathAnimation.RightFirst 
       anchorPoint: Qt.point(box.width/2, box.height/2) 
       path: myPath1 
      } 

      onStopped: { 
       console.log("test") 

       pathAnim.path = myPath2; 

       mySeqAnim.start(); 
      } 
     } 

     Path { 
      id: myPath1 
      startX: 50; startY: 100 

      PathLine { x: 300; y: 100 } 

      onChanged: canvas.requestPaint() 
     } 

     Path { 
      id: myPath2 
      startX: 300; startY: 100 

      PathLine { x: 50; y: 100 } 

      onChanged: canvas.requestPaint() 
     } 

     Rectangle { 
      id: box 

      x: 25; y: 75 
      width: 50; height: 50 
      border.width: 1 
      antialiasing: true 

      Text { 
       anchors.centerIn: parent 
      } 
     } 
    } 
} 
+0

おかげで、QAbstractAnimationは方向プロパティを持っている原因は、私はQMLのアニメーションはアニメーションを制御するために同じ能力を持たなければならないと思いました。なぜQtがこれをサポートしていないのか、本当に不思議です。 – Jiu

+0

QMLはQtではありません。 QMLにはすべてのQt API機能がありません。いずれにしても、あなたの要件に応じてC++/Qtを使ったQML(プラグインかもしれませんが、 ) – Tarod

関連する問題