• Advertisement
Sign in to follow this  

Delta time problems??

This topic is 2896 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey guys, I am trying to make my game run with delta time, but I am 1) either running into problems 2) not doing it right, which would take us back to number 1 :p I am coding in SDL and what I am doing here is calling Process with delta time, Tick is the current ticks, and previous time is set at the end of the frame. Game_Speed is defined at 60, and divided by 1000 because it is in miliseconds.
int Ticks = GameTimer.get_ticks();
CurrentState->Process(GameObjects, (((Ticks - PreviousTime) * GAME_SPEED) / 1000));
At the end of the tick function this is in, I set previoustime to current ticks.
PreviousTime = GameTimer.get_ticks();
Ok, inside process I am trying to make a object fade in... but it doesn't seem to want to work.. I don't know what I am doing wrong, I have been trying solve it for a while and now it's just getting annoying.
static int alpha = 0;
alpha += 25 * DeltaTime;
SDL_SetAlpha(Objects["Title"]->Surface, SDL_SRCALPHA, alpha);
If there is anything else you might want to know, just drop a reply.. thanks :D. Regards, Fouf.

Share this post


Link to post
Share on other sites
Advertisement
Have you attached a debugger and inspected the delta value being passed into Process? At first glance, I suspect that since you're using integers everywhere your delta time is being truncated to 0 due to integer division when it really needs to be a floating-point.

Share this post


Link to post
Share on other sites
!!! You are right, I was just thinking that maybe because it keeps evaluating to zero, I will turn it into floats, thank you VERY much for your input.

Share this post


Link to post
Share on other sites
It works, thank you very much Zipster! Something stupid as this will (hopefully) not happen again.

Regards, Fouf.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement