ok, what i learned from the implementation of spine in QML is that animations are fast.
so what i wanted to do was to let a series sprites fly to some random points and follow each other.
with speed in mind I figured out the following:
I needed a Dynamic creation of a path:
PathCreator.qml
import Felgo 3.0
import QtQuick 2.7
Item {
id: item
property variant arr : []
property variant path : null
property int startx : 0
property int starty : 0
function createObject() {
var len=arr.length,i,s = 'import QtQuick 2.7; Path {'+ "\n"
s += ' startX:' + startx + '; ' + "\n"
s += ' startY:' + starty + '; '+ "\n"
for(i=0;i<len;i++) {
s += ' PathCurve { x: ' + arr[i].xp + '; y:' + arr[i].yp + ' }' + "\n";
s += ' PathAttribute { name: "myscale"; value:' + arr[i].s + ' }' + "\n";
}
s += '}'+ "\n"
console.log(s)
path = Qt.createQmlObject( s, item);
}
}
And i wanted an enemy to follow that path:
Enemy1.qml
import Felgo 3.0
import QtQuick 2.7
EntityBase {
entityId: "enemy1"
entityType: "enemy"
id: item
property variant myPath : null
property alias pathAnim : pAnim
property double imgScale: 0.4
property int delay: 0
property int animTime: 10000
Image {
id:img
source:"../../assets/gfx/enemy1/enemy1.png"
scale: imgScale
}
BoxCollider {
anchors.fill: img
}
SequentialAnimation {
id:seqAnim
PauseAnimation { duration: delay }
PathAnimation {
id:pAnim
target: item
path : myPath
duration: animTime
}
// running:true
}
Component.onCompleted: {
start()
}
function start() {
seqAnim.start()
}
}
and some kind of level Manager who will manage paths and triggers off the enemies
import Felgo 3.0
import QtQuick 2.7
import "../common"
Item {
id: item
anchors.fill: gameWindowAnchorItem
property variant scene : null
property variant path1
property variant enemies : []
PathCreator {
id:p1
}
function createRndPath() {
var i;
p1.startx = scene.width + 300
p1.starty = scene.height >> 1
for(i=0;i<20;i++) {
p1.arr.push( {xp:200 + parseInt(Math.random()*scene.width-200), yp:150+parseInt(Math.random()*scene.height-300), s:Math.random()} )
}
p1.arr.push( {xp:p1.startx, yp:p1.starty, s:1} )
p1.createObject();
}
function createEneies1() {
//-- create enemies
var i
for (i=0;i<10;i++) {
var en = Qt.createComponent("Enemy1.qml");
en.createObject( item, {myPath:p1.path, delay:100*i, x:p1.startx, y:p1.starty, z:100-i})
enemies.push( en );
}
}
Component.onCompleted: {
createRndPath()
createEneies1()
}
}
i have a box collider in the enemy and that causes some sprites to be visible in the startup
when i remove the boxcollider everysprite starts outside the screen on the right side.
here is my PhysicsWorld code:
PhysicsWorld {
id: world
// physics is disabled initially, and enabled after the splash is finished
running: true
gravity.y: 9.81
z: 10 // draw the debugDraw on top of the entities
// these are performance settings to avoid boxes colliding too far together
// set them as low as possible so it still looks good
updatesPerSecondForPhysics: 60
velocityIterations: 5
positionIterations: 5
debugDrawVisible: true
}