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...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

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