How can I create an update function in javascript/jquery?
An update function is a function that is run at each step in the game, say 60 times a second for example. It is used a lot in game development.
How can I make something like this in jquery?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
SetInterval will be useful to you in this instance.
You can use it like this –
This code will execute a function named
callbackeverydelaymiliseconds.To stop the timer, you can use the
clearInterval()method.As I stated, the intervals are defined in milliseconds so in order for your callback to execute 60 times a second you would need to pass 16 or 17 milliseconds as the
delayparameter.