Mike018

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.

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();

 

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

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.

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

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.