diff options
author | Mitchell Stokes <mogurijin@gmail.com> | 2012-12-21 06:28:59 +0400 |
---|---|---|
committer | Mitchell Stokes <mogurijin@gmail.com> | 2012-12-21 06:28:59 +0400 |
commit | f2f2b6153a2a818ca940a4df5b7dafc743ef2d2f (patch) | |
tree | a6562a6c389b7f3e99461dda1245b1037b78a020 /source/gameengine/GameLogic/Joystick | |
parent | 26752e8b3a367a7c5161ad7418e910bb2ce6ee5d (diff) |
BGE: Adding a Python interface for handling joysticks without needing logic bricks. These new SCA_PythonJoystick objects can be accessed using bge.logic.joysticks, which is a list of joysticks. The length of the list is the number of maximum supported joysticks, and indexes that do not have a joystick available are set to None. This means joysticks can be checked for using something like:
if bge.logic.joysticks[0]:
activate_player_one()
if bge.logic.joysticks[1]:
activate_player_two()
etc..
The interface exposed by SCA_PythonJoystick is very similar to the joystick logic brick except for one key difference: axis values are normalized to a -1.0 to 1.0 range instead of -32767 to 32767, which is what the logic brick exposed.
Diffstat (limited to 'source/gameengine/GameLogic/Joystick')
-rw-r--r-- | source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp | 9 | ||||
-rw-r--r-- | source/gameengine/GameLogic/Joystick/SCA_Joystick.h | 5 |
2 files changed, 14 insertions, 0 deletions
diff --git a/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp b/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp index 8b343be8226..b7fbe958c86 100644 --- a/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp +++ b/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp @@ -321,3 +321,12 @@ int SCA_Joystick::pAxisTest(int axisnum) return 0; #endif /* WITH_SDL */ } + +const char *SCA_Joystick::GetName() +{ +#ifdef WITH_SDL + return SDL_JoystickName(m_joyindex); +#else /* WITH_SDL */ + return ""; +#endif /* WITH_SDL */ +} diff --git a/source/gameengine/GameLogic/Joystick/SCA_Joystick.h b/source/gameengine/GameLogic/Joystick/SCA_Joystick.h index 912484a2fe5..dd9fbefa545 100644 --- a/source/gameengine/GameLogic/Joystick/SCA_Joystick.h +++ b/source/gameengine/GameLogic/Joystick/SCA_Joystick.h @@ -192,6 +192,11 @@ public: * Test if the joystick is connected */ int Connected(void); + + /** + * Name of the joytsick + */ + const char *GetName(); }; #endif |