Sign in to follow this  
RayXu

How to execute every second?

Recommended Posts

How can I run it every second or every 0.5 seconds?

I try 

const seconds = 0;
app.ticker.add(delta => {
  seconds += 1 / 60;
  if(seconds >= 0.5 ){
    console.log('alert!');
  }
});

There doesn't seem to be a very stable operation.

 

Share this post


Link to post
Share on other sites

Welcome to the forums!

"1 / 60 * delta" or "ticker.deltaMs" https://github.com/pixijs/pixi.js/blob/3ffe52d29aedd79a5a281b4a6032e7c95f5ea98c/packages/ticker/src/Ticker.ts#L493

PixiJs does not have a scheduler, only a basic ticker for RAF.

Here's scheduler in a plugin https://github.com/Nazariglez/pixi-timer/ As far as I remember, its detached from PixiJS enough to work with anything >3.0.8 , even with v5. In case you use modern es6 modules, you  PIXI in global scope for it to work (like for other pixi vanilla modules, https://github.com/pixijs/pixi-layers#webpack-browserify-angular )

As usual, explanation why dont we have those functions in main package: we really care about size of our packages and dont want to force users on using our API's for trivial things. We provide renderer expertise.

Edited by ivan.popelyshev

Share this post


Link to post
Share on other sites

Thx :)

oh...Turned out to be used...

"1 / 60 * delta" or "ticker.deltaMs"

This can do what I want! Now I use the following code instead.

He should be fine.

const seconds = 0;
app.ticker.add(delta => {
  seconds += (1 / 60) * delta;
  if(seconds >= 0.5 ){
    console.log('alert!');
  }
});

but...pixi-timer I don’t understand how to use?

Because I will update the screen through time judgment during recycling.

Finally thank you @ivan.popelyshev :D

 

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...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.