putting checks into update() after a certain time?

Recommended Posts

I have a boolean variable that is changed to true after a certain time to tell update() to start looking to see if the user has finished interacting with everything. But I have to always check for that variable in the update method even though 95% of the game it doesn't need to be there. Is there a way for the update not to check if this variable is true or false, and for the things I need update to check for just be injected into the update method at a certain time?

Share this post

Link to post
Share on other sites

use Promises, they are designed to that kind of tasks.


some code example:

const interaction = id => {
  console.log(`start ${id}`);
  let complete = null;
  const promise =  new Promise(done => {
    complete = () => {
      console.log(`end ${id}`);
  return {

const i1 = interaction('i1');
const i2 = interaction('i2');

]).then(() => console.log('all done'));



Share this post

Link to post
Share on other sites

Is there anything else in the update function? Because if not you can just set sprite.update = ... when you are ready for checks.

If there is something just leave it with the boolean, the CPU power you can save is probably not worth it spending even 5min of your time with it ;-)

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.