SFML community forums
Help => General => Topic started by: CytraL on July 30, 2010, 01:49:53 pm
-
Hi.... sorry for this very noob question but... i'm starting with "Game Programming" and for me more algoritms are confuse...
Ok... i have problems when i try sync box2D World with the "Game Loop"... SFML works fine... but box2D update positions & forces very fast in Linux and ~fast in Windows.....
TIMESTEP DECLARATION:
const float TIMESTEP = 1.0f / 60.0f;
GAMELOOP:
//Update Box2D
if (time_step_box2D.GetElapsedTime() >= 0.001)
{
world.world->Step(TIMESTEP, 10);
time_step_box2D.Reset();
}
//updatePhysics();
//Update Camera Pos
camera.move();
if (!world.paused && time_step.GetElapsedTime() >= TIMESTEP) {
//world.world->Step(TIMESTEP, 10);
//screen.Clear();
draw_game();
draw_player_hud();
screen.Display();
time_step.Reset();
}
//CPU by happy :)
#ifndef __WIN32
usleep(1);
#else
Sleep(1);
#endif
Sry for my bad english :\
-
//CPU by happy :)
#ifndef __WIN32
usleep(1);
#else
Sleep(1);
#endif
Why don't you use sf::Sleep(), but with a parameter adapted to the frame time?
Anyway, the easiest approach is still to call sf::RenderWindow::SetFramerateLimit() with a desired value.
-
Ok now i have this:
LIMIT FRAME RATE:
screen.SetFramerateLimit(60);
RATIO PIXELS:
const float RATIO = 30.0f;
GAMELOOP:
if (!world.paused)
{
world.world->Step(screen.GetFrameTime(), 10);
camera.move();
draw_game();
screen.Display();
}
sf::Sleep(0.01);
And now.. works very slow (Similar to play in the Moon).... ¿How Sync box2D???? :S
Download Demo Game Win x86: Triog v0.1.1.2a (http://filebeam.com/58aaa6b80b441e511ed5606c544abb32)
Move with Keys: A-D-SPACE-MOUSE1
-
Can't help but I wanted to say I like it :o The only issue is that sometimes it's not possible to jump while walking.