Jump to content

Alternatives to on(Shake)Complete?


Recommended Posts

I've been using `game.camera.onShakeComplete` for running functions after animations are complete, but each time it adds a new instance to be run.

I've been using 

game.camera.shake(0.02, 250, true, Phaser.Camera.SHAKE_HORIZONTAL, true);
game.camera.onShakeComplete.add(function(){runFunction()}, this)

to run my code, but I just realised that this adds another function to be run each time, and I can't really have just one for the entire game because they need to do different things.

My questions really boil down to:

  1. Can I have a callback per game.camera.shake or can I only have one global one?
  2. Can I clear game.camera.onShakeComeplete so I can add a new one each time? It's probably not that efficient but it'd work.
  3. Is there a way to pass arguments from game.camera.shake to the onShakeComplete so I can have a switch statament in there or something?


Link to comment
Share on other sites

camera.onShakeComplete.addOnce(a, this);
camera.onShakeComplete.add(callback, context, priorityID, arg1, arg2, etc);

addOnce will add a single callback. So it doesn't matter how many times 'complete' runs, the callback is only fired once. Once fired you can add it again.

removeAll removes all bound callbacks from the signal.

The final line shows how to pass arguments.

Link to comment
Share on other sites

  • 2 years later...

  • Recently Browsing   0 members

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