Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple callbacks #120

Closed
Kalabasa opened this issue May 7, 2014 · 5 comments
Closed

Multiple callbacks #120

Kalabasa opened this issue May 7, 2014 · 5 comments

Comments

@Kalabasa
Copy link

Kalabasa commented May 7, 2014

Can we allow multiple callbacks instead of one per event?

Example usage:

// add two onComplete callbacks
tween.onComplete(func1);
tween.onComplete(func2);

I actually implemented this partially (only for onComplete callbacks) so will this be a useful addition?

This is the actual use case (why I implemented this feature):

function enqueue_tween(tween){
    if(tween_chain_last){
        tween_chain_last.chain(tween);
    }else{
        tween.start();
    }
    tween_chain_last = tween;
    tween_chain_last.onComplete(function(){
        if(tween_chain_last == tween){
            tween_chain_last = null;
        }
    });
}

I used this for sequencing on the fly.

@sole
Copy link
Member

sole commented May 7, 2014

Hi!

So I don't quite understand how your use case works - you're chaining tweens when "sequencing on the fly"? -- maybe I didn't quite get it.

If I wanted to run multiple callbacks when something happened, I would build a callback function that called several callbacks. Does it make sense?

@sole
Copy link
Member

sole commented Jun 16, 2014

Closing per lack of activity, reopen if you still need it or want to discuss this further!

@sole sole closed this as completed Jun 16, 2014
@accidentallyc
Copy link

Hello, reopening. Sorry for this! I first experienced this programming idiom on Phaser.
I think a better example of a use case would be something like this ->

 function move (PlayerOrObject){
  return tween(...).onComplete( ... ) // tween something then cleanup
}

function movePlayer(){
  let passedTween = move( Some_Player )
  return passedTween.onComplete( ... ) // update something related to player
}

function mainTutorial(){
  movePlayer().onComplete(function(){
    alert( "Good job!")
  })
}

In this example, the tween is being passed around . It's not a terribly important feature but yeah.

In my custom version of three js i modified the onComplete fn to be something like this to chain it

  if( _onCompleteCallback ){
      let temp = _onCompleteCallback
      _onCompleteCallback = function(){
        temp(),callback()
      };
    }else{
      _onCompleteCallback = callback;
    }

Atleast that way, there would'nt be too much refactoring required.

@mikebolt
Copy link
Contributor

mikebolt commented Dec 19, 2016 via email

@accidentallyc
Copy link

accidentallyc commented Dec 19, 2016 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants