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

Author Topic: Real-time inputs, rotate a square.  (Read 1782 times)

0 Members and 1 Guest are viewing this topic.

Snovind

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Real-time inputs, rotate a square.
« on: March 12, 2011, 08:52:00 pm »
Hi.
I have some problems with input, when I try to rotate the square it stops for like 0.1 sec right after I press the key, and then it continue the rotation.

Code: [Select]

#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>

int main()
{

sf::RenderWindow Game(sf::VideoMode(640, 480, 32), "Rotate");
Game.SetFramerateLimit(64);

sf::Shape Firkant;

Firkant.AddPoint(300, 300);
Firkant.AddPoint(400, 300);
Firkant.AddPoint(400, 400);
Firkant.AddPoint(300, 400);
Firkant.SetCenter(350.0f,350.0f);
Firkant.Move(300.0f, 200.0f);

const sf::Input& Input = Game.GetInput();

while(Game.IsOpened())
{
sf::Event Event;

while(Game.GetEvent(Event))
{

if (Event.Type == sf::Event::Closed)
Game.Close();

if (Input.IsKeyDown(sf::Key::Down))
Firkant.Rotate(10);
}

Game.Clear();

Game.Draw(Firkant);

Game.Display();
}
return EXIT_SUCCESS;
}

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Real-time inputs, rotate a square.
« Reply #1 on: March 12, 2011, 10:05:15 pm »
Don't put this code inside your event loop, otherwise it will be executed only when an event is triggered.
Laurent Gomila - SFML developer

Snovind

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Real-time inputs, rotate a square.
« Reply #2 on: March 13, 2011, 12:15:37 am »
I see, okey thanks alot!  :D

 

anything