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

Author Topic: Can't make Joystick work  (Read 6859 times)

0 Members and 1 Guest are viewing this topic.

Sheygox

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
Can't make Joystick work
« on: December 10, 2012, 03:17:36 am »
Hi. I'm really sorry for my noob questions, but I'm pretty new to all this. The thing is I donĀ“t know how to make Joystick works. For Example, I have this code:

int parsekey() {
    char k;
    if (_kbhit() == 0) return 0;
        k = _getch();
    switch (k){
    case 'w': if (movedir != 3) {movedir = 1;} return 0; break;
    case 'a': if (movedir != 4) {movedir = 2;} return 0; break;
    case 's': if (movedir != 1) {movedir = 3;} return 0; break;
    case 'd': if (movedir != 2) {movedir = 4;} return 0; break;
    case 'p':
        gotoxy(console_x / 2 - 5, console_y / 2 - 1);
        printf ("P A U S E D");
        do { k = _getch(); } while (k != 'p');
        pos p; p.y = (world_y) / 2 - 1;

        for (   p.x  = (world_x) / 2 - 5;
                p.x <= (world_x) / 2 + 5;
                p.x++)

                render_pos(p);
        break;
    case 27: // esc
        return 1;
        break;
    }
    return 0;
}

This is an actual code intended to move a character, and it is functionally working. What I want to do is make use of the joystick function. I have Code::Blocks and SFML 1.6 already working and well configured, but maybe I'm missing something (I have followed THIS tutorial).
So, what I started doing is adding this lines just to make sure it is compilling.

    float x;
    x =  sf::Input::GetJoystickAxis(1, sf::Joy::AxisX);

And I have the following error:
cannot call member function 'float sf::Input::GetJoystickAxis(unsigned int, sf::Joy::Axis) const' without object
As I said, I'm pretty noob with all this, so I don't even know what's that error meaning. Please, if you could help I would be really gratefull. If you need to know something more, please tell. I need to have this working.

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Can't make Joystick work
« Reply #1 on: December 10, 2012, 03:39:52 am »
I'm not even going to comment about the crazy contraption that you have going on there using kbhit and getch.....

Quote
cannot call member function 'float sf::Input::GetJoystickAxis(unsigned int, sf::Joy::Axis) const' without object
That says it all, you need sf::Input object to get inputs from it, you can get reference to sf::Input of a window using this function:
http://www.sfml-dev.org/documentation/1.6/classsf_1_1Window.php#ace1eacb2f3ba2ed15dcc5028d0c5df6d
in 2.0 you could do that without a need for window.
Back to C++ gamedev with SFML in May 2023

Sheygox

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
Re: Can't make Joystick work
« Reply #2 on: December 10, 2012, 05:43:42 am »
Thanks for the Answer  :) - But unfortunately, I'm stuck again with another error. I changed the code of that line and now it is:

x =  sf::Window::GetInput.GetJoystickAxis(0,sf::Joy::AxisX);

The error is:
request for member 'GetJoystickAxis' in 'sf::Window::GetInput', which is of non-class type 'const sf::Input& (sf::Window::)()const'

This time, I'm more disoriented than before. I didn't use v2.0 because I thought it was relatively new, and it wouldn't have enough documentation to learn. I will give it a try, but if you could figure out why I keep getting that error, you would really help me.
By the way, thanks again!

thePyro_13

  • Full Member
  • ***
  • Posts: 156
    • View Profile
Re: Can't make Joystick work
« Reply #3 on: December 10, 2012, 07:10:03 am »
You have the same problem as you did before. GetInput is a non-static member function. You need to call GetInput on an actual instance of sf::Window.

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: Can't make Joystick work
« Reply #4 on: December 10, 2012, 09:09:09 am »
What I want to do is make use of the joystick function. I have Code::Blocks and SFML 1.6 already working and well configured, but maybe I'm missing something (I have followed THIS tutorial).
Good, but why didn't you also read the other tutorials then? ;)
Read [SFML 1.6] Handling events, especially the "Getting real-time inputs" paragraph.

And yes you need a window to get inputs, do you have one?
« Last Edit: December 10, 2012, 09:13:00 am by G. »

Sheygox

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
Re: Can't make Joystick work
« Reply #5 on: December 10, 2012, 11:08:40 pm »
Thanks a lot for your answers. I am having a headache with this. Every time I think I am getting close to what I want, a nwe problem appears. First of all, this is the final code.

   x =  sf::Window().GetInput().GetJoystickAxis(0, sf::Joy::AxisX);

And it seems it is working, because I didn't get any errors when I was compiling.
The big problem: Code::Blocks never finish the compilation. Check this out:


Link to the image

It is just freezing there. The only thing I can do is abort the compilation.

Maybe I'm misunderstanding this whole library. I don't want to open any other window. My game it is just a Snake in ascii.


Link to the picture

I just want to be able to control its movement with 4 buttons in a Joystick. Does the Version 2.0 allows me to do this? without opening any window?
« Last Edit: December 11, 2012, 12:08:24 am by Sheygox »

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Can't make Joystick work
« Reply #6 on: December 10, 2012, 11:28:27 pm »
These pictures have error 403 on them.
Yes, 2.0 allows you to get keyboard, mouse and joystick input without a window.
Back to C++ gamedev with SFML in May 2023

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Can't make Joystick work
« Reply #7 on: December 10, 2012, 11:30:38 pm »
Quote
Does the Version 2.0 allows me to do this? without opening any window?
Absolutely, switching to SFML 2 is the solution to your problem.

You should have said earlier that you wanted to do that without a window. So that we could understand why you made so many syntax errors ;)
Laurent Gomila - SFML developer

Sheygox

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
Re: Can't make Joystick work
« Reply #8 on: December 11, 2012, 12:13:52 am »
You should have said earlier that you wanted to do that without a window. So that we could understand why you made so many syntax errors ;)

Yeah, sorry for that. As I said, I'm a newbie. I will try v2.0 and keep you updated with my future problems ;D
Thank you for all the help, you are an awesome community

Sheygox

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
Re: Can't make Joystick work
« Reply #9 on: December 11, 2012, 02:36:29 am »
I finally made the transition to v2.0 - I have followed this guide and noticed that the Joystick function is Static, so I configured my build options according the basic tutorial

I just wrote the line sf::Joystick::update(); just to test if I can compile the program, so my function is this:

int parsekey() {
    sf::Joystick::update();
    char k;
    if (_kbhit() == 0) return 0;
        k = _getch();
    switch (k){
    case 'w': if (movedir != 3) {movedir = 1;} return 0; break;
    case 'a': if (movedir != 4) {movedir = 2;} return 0; break;
    case 's': if (movedir != 1) {movedir = 3;} return 0; break;
    case 'd': if (movedir != 2) {movedir = 4;} return 0; break;
    case 'p':
        gotoxy(console_x / 2 - 5, console_y / 2 - 1);
        printf ("P A U S E D");
        do { k = _getch(); } while (k != 'p');
        pos p; p.y = (world_y) / 2 - 1;

        for (   p.x  = (world_x) / 2 - 5;
                p.x <= (world_x) / 2 + 5;
                p.x++)

                render_pos(p);
        break;
    case 27: // esc
        return 1;
        break;
    }
    return 0;
}

Now, the error I'm having it's the next one:


I don't need to say I don't get this:
undefined reference to `_imp___ZN2sf8Joystick6updateEv'
What? I have to define the sf::joystick somewhere? Isn't is enough with just including <SFML/Window.hpp>?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Can't make Joystick work
« Reply #10 on: December 11, 2012, 08:07:49 am »
You must link to sfml-window.
Laurent Gomila - SFML developer

Sheygox

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
Re: Can't make Joystick work
« Reply #11 on: December 11, 2012, 03:55:24 pm »
Laurent, as I said, I have followed step by step from here (with Static options).

This is how my build options are:


RELEASE


DEBUG


And I also tried simply writing sfml-window and sfml-system, but I'm getting the same error

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Can't make Joystick work
« Reply #12 on: December 11, 2012, 04:10:39 pm »
SFML_STATIC (with an underscore), not SFML-STATIC.
Laurent Gomila - SFML developer

Sheygox

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
Re: Can't make Joystick work
« Reply #13 on: December 11, 2012, 05:08:31 pm »
Thanks for the answer, I changed that, but I'm still getting the same error. It's really weird though. I have also tried to find a finished project using sf::Joystick but with no luck at all.
I have had a great response from this community, I'm really considerating money donation right now.
Laurent, if you think of something that could help me solve this, please let me know

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Can't make Joystick work
« Reply #14 on: December 11, 2012, 05:48:52 pm »
You can't get a linker error that contains "_imp___" if you set SFML_STATIC right.

Have you tried a complete rebuild?
Laurent Gomila - SFML developer

 

anything