import QtQuick 2.12
import QtQuick.Window 2.0
import QtQuick.Controls 2.4
Window{
id: window
width: 680
height: 320
visible: true
Canvas {
id: canvas
anchors.fill: parent
antialiasing: true //抗锯齿
onPaint: {
var context = getContext("2d")
context.clearRect(0, 0, width, height) //清屏
context.strokeStyle = "red" //设置笔的颜色
context.path = pathAnim.path //设置路径
context.stroke() //绘制已定义的路径
}
}
PathAnimation {
id: pathAnim
running: true
loops: Animation.Infinite //无限循环
duration: 5000 //单词动画时间为5S
easing.type: Easing.InQuad //设置动画的缓和曲线,此时动画效果为从慢到快
target: car //设置目标对象
orientation: PathAnimation.RightFirst //运动策略,让目标的右侧在前面沿着路径移动
anchorPoint: Qt.point(car.width/4, car.height/2) //锚点的位置
path: Path {
startX: 100; startY: 100 //路径起始位置
PathSvg { //由SVG路径字符串实现路径
path: "M100 100 C600 50, 150 250, 550 250" //M moveto C curveto
}
}
}
Item {
id: car
x: 25; y: 25
width: 80; height: 38
Image{
source: "car.png"
}
}