Jump to content

Tween.pause() only works for the first "parameter"


blackgames
 Share

Recommended Posts

Hey all,

 

I have this tween for my jump-logic:

jump_tween = game.add.tween(pigs.getAt(jumped)).to( {x: x_j, y: y_j}, 400).to( {x: p.x, y: p.y}, 600);jump_tween.start();

When the player click on the "pause-button" I call:

 

jump_tween.pause(); --> and than on play jump_tween.resume(); 

 

My problem is, that the tween only stops for the first "to" (to( {x: x_j, y: y_j}, 400)

If the tween goes here: .to( {x: p.x, y: p.y}, 600) it don't stops anymore. 

 

Is this my "bug"?

 

Thank you in advance!

Link to comment
Share on other sites

I don't think this is a bug as such, more a limitation of the current provided tweening functionality. Technically you're creating several chained tweens, but the referenced tween in jump_tween is only the first tween. What's probably needed is some kind of manager similar to GSAP's Timeline functionality. Of course, GSAP works perfectly well with Phaser so by all means give it a try and see how it suits you.

 

Phaser.TweenManager does have a pauseAll method so you could do something like game.tweens.pauseAll() but that will pause every tween in the game. You could alternatively maybe try something like the following (untested) function which should in theory pause any tweens for a specified object:

function pauseTweensFor(obj) {  // first get all of the active tweens  var tweens = game.tweens.getAll();  // filter that down to an array of all tweens of the specified object  var currentTweens = tweens.filter(function(tween) {    return tween._object === obj;  });  // if we have any matching tweens for the object, cycle through all of them and pause them  if (currentTweens.length > 0) {    for (var t = 0, len = currentTweens.length; t < len; t++) {      currentTweens[t].pause();    }  }}// use like sovar pig = pigs.getAt(jumped);pauseTweensFor(pig);
Link to comment
Share on other sites

Thank you lewster32,

 

in my case is game.tweens.pauseAll() ok, because on the state that I use for there is only the one tween.

 

I tested this now and it works for the second tween (paused), but when I resumeAll() there are a new issue. 

When I paused it in the time for the first tween .to( {x: x_j, y: y_j}, 400) it works great, but when I paused in the time goes the second tween .to( {x: p.x, y: p.y}, 600)

its stoped but by resumeAll the tween not going from the place it paused but direct to the finish of the tween. 

 

I hope this is understandable. 

 

Thanks

Link to comment
Share on other sites

As I said, mine is an untested and pretty hacky way of doing what you want. I'd really recommend you look at GSAP as its tween management is really good. The Timeline functionality lets you set up lots of tweens to run in sequence, and you can pause or manipulate the sequence like it's one big tween (play it backwards, change the speed etc).

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...