s4m_ur4i Posted November 1, 2016 Share Posted November 1, 2016 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 Link to comment Share on other sites More sharing options...
s4m_ur4i Posted November 1, 2016 Author Share Posted November 1, 2016 maybe what's interesting too is: after the tween and everything after the onCompleteAdd of it; is executed: and you unpause - every value that was applied in the tweens (y, x etc) is assigned a second time, without tweening. So the character is thrown off the tweens values after unpause. There is a method that returns if an object is tweening: game.tweens.isTweening( Object ); This works fine on the characters which are climbing the ladder. But it does not work when you pause right after as described above. This seems to be an issue not caused by my code? Aren't it? regards Link to comment Share on other sites More sharing options...
Recommended Posts