SFML community forums
Help => Window => Topic started 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:
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 >.<
-
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 :
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.
-
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
-
GetFrameTime() should be a few ms, so you must enlarge the constant 5.
-
To be more precise, 5 should be replaced by the desired speed in units / second.
-
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 :))
-
ok thanks, it worked now, the failure was, that PosX and PosY are short
I tried it with floats and it works ;)
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());
}