RayXu Posted March 27, 2020 Share Posted March 27, 2020 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. ivan.popelyshev 1 Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted March 27, 2020 Share Posted March 27, 2020 (edited) 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 March 27, 2020 by ivan.popelyshev RayXu 1 Quote Link to comment Share on other sites More sharing options...
RayXu Posted March 28, 2020 Author Share Posted March 28, 2020 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 ivan.popelyshev 1 Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted March 28, 2020 Share Posted March 28, 2020 > but...pixi-timer I don’t understand how to use? Simple. Look in the code , if you like something - take it for your app. Its just someone's two-files plugin. RayXu 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.