We would like to get the coordinates and angles of multiple objects from a json file and create a playback of around 30,000~50,000 animations.
Is PhaserJS(3.60) suitable for this case?
If suitable, is it correct to use Tweens?
Is it possible to implement a seek bar function with Tweens animations?
I am currently implementing the following, but the animation starts late and the object coordinates and rotation angle are wrong.
Is it also possible to rewind the Tweens animation with the seek function?
The version of PhaserJs is 3.60.
// Seek part
const scenesIndex = Object.keys(tweensArray); // The form of tweensArray is shown below
const totalTime = Math.floor((scenesIndex.length * 100) * (startSceneNumber / 100)); // startSceneNumber contains the value of what percentage to skip.
this.tweens.getTweens().forEach((tween) =>{
tween.pause();
tween.seek(totalTime, 16.6, true);
tween.resume();
tween.targets[0].x = (tween.getValue() == 0) ? -1000 : tween.getValue();
tween.targets[0].y = (tween.getValue() == 0) ? -1000 : tween.getValue();
});
// The animation is created as follows.
// There are n animations and n + 22 tweens.
const tweensArray = {
1: [],
3: [],
5: [Tween2],
8: [Tween2],
10: [Tween2, Tween2],
14: [Tween2, Tween2, Tween2],
15: [Tween2, Tween2, Tween2, Tween2],
16: [Tween2, Tween2, Tween2, Tween2],
17: [Tween2, Tween2, Tween2, Tween2],
21: [Tween2, Tween2, Tween2],
n: [Tween2 * n],
};
/*
Methods for creating animation.
targetsObj : targetsObj is a sprite object.
this.add.sprite(-1000, -1000, 'ImgObj').setAlpha(0).setDepth(500);
imgPos : imgPos contains x and y coordinates.
angle : angle is the angle of rotation.
counter : counter is a counter for delay.
*/
createTweensAnimation(targetsObj, imgPos, angle, counter) {
const tween = this.tweens.add({
targets: TargetsObj,
x: imgPos.x,
y: imgPos.y,
duration: 100,
delay: counter * 100,
persist: true,
onStart: function() {
TargetsObj.setAngle(angle);
TargetsObj.setAlpha(1);
},
onPause: function() {
console.log("onPause");
TargetsObj.setAlpha(0);
},
onResume: function() {
console.log("onResume");
TargetsObj.setAlpha(0);
}
})
return tween
}