Sign in to follow this  
Foufs

Delta time problems??

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this