'Update' Function

How can i make a 'update' function that gets called every frame?
6 Replies
becquerel
becquerel3y ago
What does a 'frame' mean in this context?
Revolving Madness
for example a drawing function or a function that gets called everyframe for input
becquerel
becquerel3y ago
I would consider looking into how Monogame does this (it also gives you an update/draw loop for free) you're probably going to want to have a while (true) loop that checks the current time in each iteration and compares that against a saved value if it's been more than 1/60th of a second (or whatever), then go into the actual logic you want to execute the reason why i'm asking what a frame means is because if you just have a while(true) loop by itself it's going to go as fast as your CPU can manage which is probably not what you want
Revolving Madness
ya how would i implement that? cuz if u do a normal while loop it breaks
becquerel
becquerel3y ago
DateTime lastTime;

while (true)
{
var currentTime = DateTime.Now;

var difference = currentTime - lastTime;

if (difference > TimeSpan.FromMilliseconds(13.6666) continue;

ActuallyDoStuff();
}
DateTime lastTime;

while (true)
{
var currentTime = DateTime.Now;

var difference = currentTime - lastTime;

if (difference > TimeSpan.FromMilliseconds(13.6666) continue;

ActuallyDoStuff();
}
Revolving Madness
is there anyway i can set the value of the screen to an array of pixels? insted of just individually drawing each pixel one by one

Did you find this page helpful?