Skip to main content
Tweeted twitter.com/#!/StackGameDev/status/507992409360588800
Various small clarifications.
Source Link
Anko
  • 13.5k
  • 10
  • 56
  • 82

How todo I implement variable timingtime scaling?

In my game I would likewant to be able to change the game speed of the time so that, to speed up or slow down all animations and gameplay is slowed down or speed up. Ideally, this speedcould also goes below zero so thatbe set to a negative number to make everything goesgo backwards.

Basically I havetried this:

I made everything dependent toon a timetime variable which I update, updated every frame using the time from the OS. time:

void calledEveryFrame()
{
    time = System.accurateTime();
}

NowThen I tried the following but it didn't work:just scaling that time.

    lastTime = time;
    long now = System.accurateTime();
    double diff = now - lastTime;       
    time = (lastTime + diff * speed);

That obviously doesn't work, because you can't just multiply the speed times the difference because it is not called exactly regularly.

How do I do this correctly?

How to implement variable timing

In my game I would like to change the speed of the time so that all animations and gameplay is slowed down or speed up. Ideally this speed also goes below zero so that everything goes backwards.

Basically I have everything dependent to a time variable which I update every frame using the time from the OS.

void calledEveryFrame()
{
    time = System.accurateTime();
}

Now I tried the following but it didn't work:

    lastTime = time;
    long now = System.accurateTime();
    double diff = now - lastTime;       
    time = (lastTime + diff * speed);

That obviously doesn't work because you can't just multiply the speed times the difference because it is not called exactly regularly.

How do I implement time scaling?

I want to be able to change the game speed, to speed up or slow down all animations and gameplay. Ideally, this could also be set to a negative number to make everything go backwards.

I tried this:

I made everything dependent on a time variable, updated every frame from the OS time:

void calledEveryFrame()
{
    time = System.accurateTime();
}

Then I tried just scaling that time.

lastTime = time;
long now = System.accurateTime();
double diff = now - lastTime;       
time = (lastTime + diff * speed);

That obviously doesn't work, because you can't just multiply the speed times the difference because it is not called exactly regularly.

How do I do this correctly?

inIn my game iI would like to change the speed of the time so that all animations and gameplay is slowed down or speed up. ideallyIdeally this speed also goes below zero so that everything goes backwards.

basically iBasically I have everything dependantdependent to a time variable which iI update every frame using the time from the OS.

void calledEveryFrame()
{
    time = System.accurateTime();
}

now iNow I tried the following but it didntdidn't work:

    lastTime = time;
    long now = System.accurateTime();
    double diff = now - lastTime;       
    time = (lastTime + diff * speed);

thatThat obviously doesntdoesn't work because you cantcan't just multiply the speed totimes the difference because it is not called exactly regularly.

in my game i would like to change the speed of the time so that all animations and gameplay is slowed down or speed up. ideally this speed also goes below zero so that everything goes backwards.

basically i have everything dependant to a time variable which i update every frame using the time from the OS.

void calledEveryFrame()
{
    time = System.accurateTime();
}

now i tried the following but it didnt work:

    lastTime = time;
    long now = System.accurateTime();
    double diff = now - lastTime;       
    time = (lastTime + diff * speed);

that obviously doesnt work because you cant just multiply the speed to the difference because it is not called exactly regularly.

In my game I would like to change the speed of the time so that all animations and gameplay is slowed down or speed up. Ideally this speed also goes below zero so that everything goes backwards.

Basically I have everything dependent to a time variable which I update every frame using the time from the OS.

void calledEveryFrame()
{
    time = System.accurateTime();
}

Now I tried the following but it didn't work:

    lastTime = time;
    long now = System.accurateTime();
    double diff = now - lastTime;       
    time = (lastTime + diff * speed);

That obviously doesn't work because you can't just multiply the speed times the difference because it is not called exactly regularly.

edited tags
Link
clamp
  • 563
  • 2
  • 7
  • 19
Source Link
clamp
  • 563
  • 2
  • 7
  • 19
Loading