Jump to content

putting checks into update() after a certain time?


Mike018
 Share

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?

Link to comment
Share on other sites

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

https://es6console.com/jez4q039/

some code example:

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

console.log('make');
const i1 = interaction('i1');
const i2 = interaction('i2');

console.log('promise');
Promise.all([
  i1.promise,
  i2.promise
]).then(() => console.log('all done'));

console.log('trigger');
i1.complete();
i2.complete();

 

Link to comment
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 ;-)

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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