Tymski Posted March 9, 2017 Share Posted March 9, 2017 Hello! I got quite confused after reading code for pixiJS examples and basics. I have an update function in which I want to control my objects in such a way framerate doesn't affect things. How do I declare deltaTime to do this? I've seen in example one can use Ticker delta but I don't know how to use it in my loop. function update() { someObject.move( deltaTime * someValue ); renderer.render(stage); requestAnimationFrame(update); } Sorry for duplicating post, this editor is pretty weird. As I wanted to TAB to make space in my code it changed focus to Submit button. Quote Link to comment Share on other sites More sharing options...
Taz Posted March 10, 2017 Share Posted March 10, 2017 Hi Tymski. You can use the code below to calculate deltaTime. The newer versions of Pixi make it easier though. This link from the official examples shows minimal code to do what you need: Pixi Examples. var lastTime = 0; requestAnimationFrame(update); function update(time) { var deltaTime = 0; if (lastTime) { deltaTime = time - lastTime; } lastTime = time; someObject.move(deltaTime * someValue); renderer.render(stage); requestAnimationFrame(update); } Quote Link to comment Share on other sites More sharing options...
d13 Posted March 11, 2017 Share Posted March 11, 2017 There's also this: https://github.com/kittykatattack/smoothie Quote Link to comment Share on other sites More sharing options...
Tymski Posted April 3, 2017 Author Share Posted April 3, 2017 I used Date.now() to get current time and saved it in a variable. Difference between that variable and current time is the time between frames. Divided that by 16.66666 (each frame should take 16.66666 ms to get 60 frames a second). Thanks for the responses. Quote Link to comment Share on other sites More sharing options...
tywang2006 Posted April 10, 2017 Share Posted April 10, 2017 pixijs ticker passed deltaTime, you can use it, I did in my game, it is running perfectly Quote Link to comment Share on other sites More sharing options...
Tymski Posted April 29, 2017 Author Share Posted April 29, 2017 On 10.04.2017 at 4:28 PM, tywang2006 said: pixijs ticker passed deltaTime, you can use it, I did in my game, it is running perfectly Can you provide code example? Quote Link to comment Share on other sites More sharing options...
tywang2006 Posted May 4, 2017 Share Posted May 4, 2017 On 4/29/2017 at 2:17 PM, Tymski said: Can you provide code example? app.ticker.add(this.update, this); function update(detla) { //delta will be passed through in this callback } 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.