sodacrunch Posted August 11, 2013 Share Posted August 11, 2013 http://jsfiddle.net/sodacrunch/73c9W/1/ I wanted to know what the term/subject is called for telling an object to do something for X amount of seconds. For example, go left for one second and then down for 2 seconds and then right for 4 seconds, etc etc. Is it "delta time" ? Also, is my current setup correct or should I change it? I was using set interval before but switched to requestanimationframe. Quote Link to comment Share on other sites More sharing options...
Psychho Posted August 11, 2013 Share Posted August 11, 2013 Add this code to your update loop,var newTime = Date.now();deltaTime = (newTime-lastTime)/1000;lastTime = newTime;now for example if you changed if (rightDown) this.x += 5;toif (rightDown) this.x += 5*deltaTime;the movement will then be time based and x will increment by 5 every second. Quote Link to comment Share on other sites More sharing options...
sodacrunch Posted August 14, 2013 Author Share Posted August 14, 2013 thanks! I added var "lastTime = 0;" outside the loop Quote Link to comment Share on other sites More sharing options...
narushevich Posted August 17, 2013 Share Posted August 17, 2013 http://jsfiddle.net/sodacrunch/73c9W/1/ I wanted to know what the term/subject is called for telling an object to do something for X amount of seconds. For example, go left for one second and then down for 2 seconds and then right for 4 seconds, etc etc. Is it "delta time" ? Also, is my current setup correct or should I change it? I was using set interval before but switched to requestanimationframe. I guess it's called the behavior.) 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.