SFML community forums

Help => Window => Topic started by: Metaby on May 18, 2008, 09:49:10 pm

Title: [Solved] Control Game Speed without Framelimiter
Post by: Metaby on May 18, 2008, 09:49:10 pm
Hello, in the tutorial is a methode described to control the gamespeed without framelimiter... I have tried it, and to change the degrees of my angel var, to rotate the texture, it works.. but to walk forward / backward i use an complex calculation with degrees and radiants, and i dont know, where I should use the method to control the gamespee (GameSpeed * Game->GetFrameTime())
here is my calculation:


Code: [Select]
if (Game->GetInput().IsKeyDown(Key::Up) && HitStart == false && PosX > -15 && PosY > 5 && PosX < 972 && PosY < 738)
{
Backward = false;
X = 5 * cos(0.0174532925 * (Angle + 90.0));
Y = 5 * sin(0.0174532925 * (Angle + 90.0));
PosX -= (int) X;
PosY += (int) Y;
}


need help please, sorry for my bad english >.<
Title: [Solved] Control Game Speed without Framelimiter
Post by: Laurent on May 19, 2008, 02:46:35 am
If 5 is some kind of speed, then X and Y are velocity components and then they must be mutliplied by elapsed time to get the position offset to apply :
Code: [Select]
PosX -= (int) (X * Game->GetFrameTime());
PosY += (int) (Y * Game->GetFrameTime());

By the way, integers are bad for positions, you won't get a smooth motion.
Title: [Solved] Control Game Speed without Framelimiter
Post by: Metaby on May 19, 2008, 10:34:11 am
I've tried this, but my texture don't walk in the line of his sight.. and the speed isn't controled realy =(
5 was the speed constant before using the GameSpeed * Game->GetFrameTime() method, so it can be replaced..
need help please, mfg max
Title: [Solved] Control Game Speed without Framelimiter
Post by: Kernelpanic on May 19, 2008, 04:00:20 pm
GetFrameTime() should be a few ms, so you must enlarge the constant 5.
Title: [Solved] Control Game Speed without Framelimiter
Post by: Laurent on May 19, 2008, 05:05:19 pm
To be more precise, 5 should be replaced by the desired speed in units / second.
Title: [Solved] Control Game Speed without Framelimiter
Post by: workmad3 on May 19, 2008, 05:19:57 pm
and pos should be changed to using floats, as otherwise your motion will only change when your velocity happens to be more than 1 unit in the elapsed time. Let SFML worry about turning your position into integer amounts (or more precisely, OGL which can use some anti-aliasing to give sub-pixel precision to your drawing with fancy fading effects :))
Title: [Solved] Control Game Speed without Framelimiter
Post by: Metaby on May 19, 2008, 10:05:35 pm
ok thanks, it worked now, the failure was, that PosX and PosY are short
I tried it with floats and it works ;)
Code: [Select]
if (Game->GetInput().IsKeyDown(Key::Up) && HitStart == false && PosX > -15 && PosY > 5 && PosX < 972 && PosY < 738)
{
Backward = false;
X = GameSpeed * cos(0.0174532925 * (Angle + 90.0));
Y = GameSpeed * sin(0.0174532925 * (Angle + 90.0));
PosX -= (X * Game->GetFrameTime());
PosY += (Y * Game->GetFrameTime());
}