Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [Solved] Control Game Speed without Framelimiter  (Read 5627 times)

0 Members and 3 Guests are viewing this topic.

Metaby

  • Newbie
  • *
  • Posts: 23
    • View Profile
[Solved] Control Game Speed without Framelimiter
« 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 >.<
I hacked 127.0.0.1 *g*

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
[Solved] Control Game Speed without Framelimiter
« Reply #1 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.
Laurent Gomila - SFML developer

Metaby

  • Newbie
  • *
  • Posts: 23
    • View Profile
[Solved] Control Game Speed without Framelimiter
« Reply #2 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
I hacked 127.0.0.1 *g*

Kernelpanic

  • Jr. Member
  • **
  • Posts: 50
    • View Profile
    • http://eisenholz.bplaced.net
[Solved] Control Game Speed without Framelimiter
« Reply #3 on: May 19, 2008, 04:00:20 pm »
GetFrameTime() should be a few ms, so you must enlarge the constant 5.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
[Solved] Control Game Speed without Framelimiter
« Reply #4 on: May 19, 2008, 05:05:19 pm »
To be more precise, 5 should be replaced by the desired speed in units / second.
Laurent Gomila - SFML developer

workmad3

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
[Solved] Control Game Speed without Framelimiter
« Reply #5 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 :))

Metaby

  • Newbie
  • *
  • Posts: 23
    • View Profile
[Solved] Control Game Speed without Framelimiter
« Reply #6 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());
}
I hacked 127.0.0.1 *g*