Sign in to follow this  
OffbeatPatriot

My game shakes, sometimes.

Recommended Posts

So far this seems to be a problem that comes and goes away without any warning, I'm not really sure how I expect anyone to help me with this but I thought someone might have a similar experience or this is a general issue with computer graphics. I was going to post this in the graphics section but I don't really know if it's a graphics issue, I just have a suspicion it has to do with the screen not refreshing properly. Basically I've been building this game of mine and one day it seemed fairly complete, it looked nice, ran smooth, and I even had an fps counter reading about 1000 fps(If it means anything, this counter basically takes the time between iterations of the main loop and draws the inverse of that on screen). One day I come back to it and the game seems to have spontaneously developed a problem, the fps counter now seems to jump between 60 and 1000 fps, still playable but when I look at the player's character he now appears to vibrate when he moves. I don't know if posting any code will help but here is my main loop. It's in Java, tick looks at the system clock and updates the timer, getTime returns seconds, and reset turns the timer back to zero.
timer.reset();
while(running){
    delta = timer.getTime();
    Timer.tick();
    if(delta == 0){
        continue;
    }
    timer.reset();

    GameGraphics.update();
    GameGraphics.clear();
    currentState.update();
    currentState.draw();

    if(Display.isCloseRequested() || Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)){
        running = false;
    }
            
    GameGraphics.drawString(String.valueOf(1/delta), 0, 100);
}

Share this post


Link to post
Share on other sites
delta = timer.getTime();
Timer.tick();
if(delta == 0){
continue;
}
timer.reset();


Maybe its because you're resetting your timer every time your loop runs? Does getTime() update the timer, or just retrieve the delta? What does Timer.tick() do? If it updates the timer, then you're conditional will be true half of the time. That might explain why your FPS goes rapidly from 60 to 1000.

currentState.update();
GameGraphics.clear();
currentState.draw();
GameGraphics.update();


Also, shouldn't the update order go like this?
Update, clear frame, draw frame, swap buffers?

[Edited by - Slather on January 1, 2010 8:47:05 PM]

Share this post


Link to post
Share on other sites
I recently had a similar problem with some overlapping background trees appearing to vibrate (basically, not moving a uniform amount each frame).

I solved it by implementing a Think function to handle movement, and adding a think timer set to 40 milliseconds (1/50th of a frame).


void Scenery::Update( Uint32 frameTime ){

m_think.Update( frameTime );

if( m_think.TimeLimitReached() ) {
m_think.ResetTimer();
Think();
}

}

void Scenery::Think() {

m_position.UpdateX( m_velocity.GetX() * m_thinkTime );

}




This code is only for a quick prototype so you might want to make something more robust, but it should at the very least fix your problem.

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