Search the Community
Showing results for tags 'manage tweens'.
-
Usecase: Why would I stop a tween, right after it is created: So in my game you got many objects which running around and need some tweens. In particular: For climbing a ladder. The game.tweens.pauseAll(); is called when the mainmenu opens. this works pretty well, expect some case. I cannot really tell were it relies on. If it is the timing (right after the tween) or only this sort of tween. It seems only to happen on the "climbing tween". This is the code to pause all tween, which is called every time you hit "space": game.physics.arcade.isPaused = true; game.timer.pause(); game.tweens.pauseAll(); And this is a snippet of the code which is executed on collision with the ladder object, were the tweenings start: let location = this.y + this.body.height / 2; let climbDir = 0; //you can ignore this, it's just to set up the right numbers if ( location > ladderY ) { climbDir = (location - ladderY) * -1 -2; } else if ( location <= ladderY ) { climbDir = ladderY + 120 - location - 2; } //an animation plays this.animations.play('climb', 60, true); // >THIS< is the point were the tween is executed let tween2 = game.add.tween( this ).to({ y: this.y + climbDir }, 10 * Math.abs(climbDir), 'Linear' ); tween2.start(); // >NOW< when you hit space an run game.tweens.pauseAll(); <- this won't work-> The lines afterwards are executed tween2.onComplete.add(()=>{ const turn = this.animations.play('turn_back_' + this.getDirection() + '_reverse', 21, false); turn.onComplete.add(()=>{ //all this is executed even if game.tweens.pauseAll(); is called in the above moment let dir = this.getDirection() === 'right' ? 40 : -40; this.animations.play('walk_' + this.getDirection(), 60, true); let tween3 = game.add.tween(this).to({ x : this.x + dir }, 450, 'Linear'); ... even more code //all this is executed too, even if game.tweens.pauseAll(); is called in the above moment The problem is: That not only the tween does not stop, everything afterwards is executed as well. Even other tweens that are inside the "tween2.onComplete.add". I tested it a few times and it is the same behavior ever and ever again. What's stange is: if you hit "space" => pauseAll(); this would work if the tween is nearly complete. But if you hit it right after it begins, the issue I described appears. Any ideas on this? Maybe I am making something wrong.. but I am a bit stuck since it seems that tween2.onComplete is executed due to not stopable tween2 in some timing function. regards