I tried using the methods on lazyfoo's site for frame rate independence. One problem I'm having though is that my game is running at different speeds on different computers. The differences are drastic. For example, on a Core 2 Duo 2.4 ghz 2gb ram PC, the ball will move extremely fast, but the paddle moves slowly. On an Intel Centrino laptop running Win7 w/plenty of ram, the ball moves slowly, but the paddle moves fast. On older computers like a Pentium 4 2.4 ghz, 768 ram computer, the ball moves realllllllllyyyyyyy sllllooowwww. Yes, that slow.
What might be some reasons this is happening, and how can I fix it? I can only assume that the code I wrote that deals with frame rate independence is wrong. Here are the relevant parts of the code. (btw, it's a breakout clone).
Code to move the ball
bool Ball::MoveBall( Uint32 deltaTicks )
{
// X-COORDINATE
xOffset += cos( radians ) * ( ballVelocity / 1000.f ) * flipx;
ballPosition.x = (Sint16)xOffset;
.......
// Y-COORDINATE
yOffset += sin( radians ) * ( ballVelocity / 1000.f ) * flipy;
ballPosition.y = (Sint16)yOffset;
.....
}
Code to move the paddle
void Paddle::Move( Uint32 deltaTicks )
{
xOffset += xVel * ( deltaTicks / 1000.f );
paddlePosition.x = (Sint16)xOffset;
}
Main loop
while ( SDL_PollEvent( &gEvent ) )
{
handle.PaddleInput( &gEvent, stick );
if ( gEvent.type == SDL_QUIT || gEvent.key.keysym.sym == SDLK_ESCAPE )
quit = true;
}
stick.Move( time.GetTicks() );
if ( ball.MoveBall( time.GetTicks() ) )
wallSound.Play();
if ( ball.CheckPaddleCollision( stick ) )
paddleSound.Play();
if ( ball.CheckBrickCollision( brickmap ) )
brickSound.Play();
if ( ball.IsBallDead() ) {
ball.ResetBallPosition();
stick.ResetPaddlePosition();
stick.SetPaddleState( Paddle::RESET );
launched = false;
draw.GameObjects( lvl, brickmap, stick, ball );
}
draw.GameObjects( lvl, brickmap, stick, ball );
time.Start();
draw.Refresh();
{}
button. It just adds 4 spaces to each line. – Tetrad Aug 19 '11 at 07:25