Delta time problems??

Started by
2 comments, last by Foufs 14 years, 1 month ago
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.
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.
!!! 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.
It works, thank you very much Zipster! Something stupid as this will (hopefully) not happen again.

Regards, Fouf.

This topic is closed to new replies.

Advertisement