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

Author Topic: SFML 2.0 GetInput()  (Read 15432 times)

0 Members and 1 Guest are viewing this topic.

pighead10

  • Jr. Member
  • **
  • Posts: 56
    • View Profile
    • Hog Pog
SFML 2.0 GetInput()
« on: December 22, 2011, 06:36:57 pm »
What should I use instead? I know sf::input got replaced by sf::Keyboard and sf::Mouse, but I cannot find any function like GetInput() in the documentation under Window. I'm trying to achieve something like this in the 1.6 tutorial:

Code: [Select]
// Get some useless input states, just to illustrate the tutorial
        bool         LeftKeyDown     = Input.IsKeyDown(sf::Key::Left);
        bool         RightButtonDown = Input.IsMouseButtonDown(sf::Mouse::Right);
        bool         JoyButton1Down  = Input.IsJoystickButtonDown(0, 1);
        unsigned int MouseX          = Input.GetMouseX();
        unsigned int MouseY          = Input.GetMouseY();
        int          JoystickX       = Input.GetJoystickAxis(1, sf::Joy::AxisZ);
        int          JoystickY       = Input.GetJoystickAxis(1, sf::Joy::AxisY);
        int          JoystickPOV     = Input.GetJoystickAxis(1, sf::Joy::AxisPOV);
Immortui - Zombie puzzle game: http://immortui.hogpog.co.uk

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
SFML 2.0 GetInput()
« Reply #1 on: December 22, 2011, 07:27:58 pm »
Check the documentation. They are just global functions.
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

Anata

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
SFML 2.0 GetInput()
« Reply #2 on: December 23, 2011, 12:48:28 pm »
Code: [Select]
const sf::Input& Input = App.GetInput();

After that, you can use this code

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
SFML 2.0 GetInput()
« Reply #3 on: December 23, 2011, 12:53:46 pm »
Quote from: "Anata"
Code: [Select]
const sf::Input& Input = App.GetInput();

After that, you can use this code

He wants the equivalent in SFML 2 ;)
Laurent Gomila - SFML developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
SFML 2.0 GetInput()
« Reply #4 on: December 23, 2011, 12:54:56 pm »
Quote from: "Groogy"
Check the documentation.
Yes, that's the best source until the tutorials of SFML 2.0 are written.

Quote from: "Groogy"
They are just global functions.
No, they're static functions of the classes sf::Mouse, sf::Keyboard, sf::Joystick.

Quote from: "Anata"
Code: [Select]
const sf::Input& Input = App.GetInput();
He uses SFML 2, so sf::Input won't help him.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

nitrix

  • Newbie
  • *
  • Posts: 27
    • View Profile
SFML 2.0 GetInput()
« Reply #5 on: December 23, 2011, 03:23:12 pm »
[...]
Event someEvent;
window.PollEvent(someEvent);
[...]
switch (someEvent.type) {
case sf::Event::KeyPressed:
//event.key.code....
//sf::Keyboard::Escape...
}

The event structure will get filled with all the data needed about the event. event.type tells you what kind of event it is (mouse, keyboard, etc). Process everything in a switch case (: Then you can set your own booleans and stuff.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
SFML 2.0 GetInput()
« Reply #6 on: December 23, 2011, 03:39:16 pm »
He wants the equivalent of sf::Input, not events (which haven't changed much).
Laurent Gomila - SFML developer

nitrix

  • Newbie
  • *
  • Posts: 27
    • View Profile
SFML 2.0 GetInput()
« Reply #7 on: December 23, 2011, 04:58:15 pm »
I didn't know there was a difference. Both are very similar and events are even easier to work with.

phufhi

  • Newbie
  • *
  • Posts: 8
    • View Profile
SFML 2.0 GetInput()
« Reply #8 on: December 23, 2011, 05:38:33 pm »
You can find the equivalent code for sf::input in the sfml 2 documentation.

However, I would like to know why GetMouseX() and GetMouseY() have been replaced with GetPosition(), which returns a "Vector2i". It seems to me that this is less convenient.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
SFML 2.0 GetInput()
« Reply #9 on: December 23, 2011, 05:50:47 pm »
Quote
However, I would like to know why GetMouseX() and GetMouseY() have been replaced with GetPosition(), which returns a "Vector2i". It seems to me that this is less convenient.

See by yourself:
Code: [Select]
// current API

int x = sf::Mouse::GetPosition().x;
int y = sf::Mouse::GetPosition().y;
sf::Vector2i pos = sf::Mouse::GetPosition();

Code: [Select]
// what you want

int x = sf::Mouse::GetPositionX();
int y = sf::Mouse::GetPositionY();
sf::Vector2i pos(sf::Mouse::GetPositionX(), sf::Mouse::GetPositionY());

What I want to highlight is that extracting components from a vector is just one extra character to write, whereas constructing a vector from separate components can be really verbose.
And although it doesn't have a significant impact, the second solution would require to call the same underlying OS-specific function twice.
Laurent Gomila - SFML developer

phufhi

  • Newbie
  • *
  • Posts: 8
    • View Profile
SFML 2.0 GetInput()
« Reply #10 on: December 23, 2011, 06:13:16 pm »
Thanks, Laurent!
I am new to sfml and relatively new to programming.
I did not know you could get the coordinates this way!

 

anything