divers Posted October 18, 2018 Share Posted October 18, 2018 Hi guys. I have a little problem with tweens timeline. I made a demo with my problem: http://zabka229.ct8.pl/ Just click a couple of times where you want to go really fast. Sometimes character is getting extra speed and if you click the same spot multiple times the character stops. moveCharacter(path) { if (this.movement && this.movement.isPlaying()) { this.movement.destroy(); } const tweens = []; for (let i = 0; i < path.length - 1; i++) { const ex = path[i + 1].x; const ey = path[i + 1].y; tweens.push({ targets: this.player, x: { value: ex * this.map.tileWidth, duration: 200 }, y: { value: ey * this.map.tileHeight, duration: 200 } }); } this.movement = this.tweens.timeline({ tweens: tweens }); } I think that I should wait for finishing first tween in old timeline and then create new one, but I know how to check which tween is currently playing. Anyone have idea? Link to comment Share on other sites More sharing options...
divers Posted October 19, 2018 Author Share Posted October 19, 2018 Is there any event I could use to detect change between tweens in timeline? Link to comment Share on other sites More sharing options...
divers Posted October 20, 2018 Author Share Posted October 20, 2018 So I figured it on my own, here's what I did to detect current tween: if (this.movement && this.movement.isPlaying()) { const progress = this.movement.elapsed; const currentTweenIndex = this.movement.data.findIndex(tween => { return (tween.calculatedOffset + tween.duration) > progress; }); const currentTween = this.movement.data[currentTweenIndex]; if (currentTween) { currentTween.setCallback('onComplete', () => { this.movement.destroy(); this.findPath(toX, toY); }, []); } } where this.movement is current timeline. Have a good day! GreenCloversGuy and shahwarnisar 1 1 Link to comment Share on other sites More sharing options...
Recommended Posts