I am developing a platformer in Pygame with the eventual hope of releasing it on Steam.
I am currently trying to add input support for multiple controllers.
To do this, I am using the Pygame joystick module, which allows a connected controller to send input events to my event queue (the event types are JOYBUTTONDOWN, JOYBUTTONUP, and JOYAXISMOTION).
I want to have input support for at least keyboards, Xbox 360 controllers, Xbox One controllers, and PS4 controllers.
The problem, of course, is that these controllers all use different button IDs.
One way I thought of getting around this was to call a function in my event processing code which could convert input from any of these devices to a more abstract event tag. For example, keyboard presses of “a”, Xbox 360 controller presses of left on the D-pad, and negative motion on the seventh axis of a PS4 controller would all set an abstract “mapped_event” attribute to “left”. I could then use this “mapped_event” attribute in my player sprite’s process_event() method, which moves him based on event input.
Here’s a sketch of how that conversion code would look:
def map_event(event): # KEYBOARD BUTTON PRESSES if event.type == pg.KEYDOWN: if event.key = K_RIGHT: mapped_event = "right" elif event.key == K_LEFT: mapped_event = "left" # CONTROLLER BUTTON PRESSES elif event.type == pg.JOYBUTTONDOWN: if joystick == "Xbox360 controller": if event.button == 3: mapped_event = "right" elif event.button == 2: mapped_event = "left" # CONTROLLER AXIS MOTION elif event.type == pg.JOYAXISMOTION: if joystick == "Xbox360 controller": if event.axis == 1: if event.value == 1: mapped_event = "left" elif event.value == -1: mapped_event = "right" elif joystick == "PS4 controller": if event.axis == 3: if event.value == 1: mapped_event = "left" elif event.value == -1: mapped_event = "right" return mapped_event
From what I can tell, this is the way a lot of people recommend getting around the inconsistent controller issue. For example, I think this is what is meant when people speak about an “intermediate layer” of input processing and “mapping from real buttons to game concepts”. Please correct me if I’m interpretting this wrong.
My question is:
How can I extend this method, (or an alternative), to also support all controllers which use, say, XInput/DirectX (according to this answer, a lot of aftermarket controllers use these), while handling multiple OSes?
How can one impliment multiple control schemes for a single player?
Correct way to abstract an XBox Controller
Unity3D Joystick Buttons Xbox360 & PS3 have Inconsistent Button Inputs?
✓ Extra quality
ExtraProxies brings the best proxy quality for you with our private and reliable proxies
✓ Extra anonymity
Top level of anonymity and 100% safe proxies – this is what you get with every proxy package
✓ Extra speed
1,ooo mb/s proxy servers speed – we are way better than others – just enjoy our proxies!
USA proxy location
We offer premium quality USA private proxies – the most essential proxies you can ever want from USA
Our proxies have TOP level of anonymity + Elite quality, so you are always safe and secure with your proxies
Use your proxies as much as you want – we have no limits for data transfer and bandwidth, unlimited usage!
Superb fast proxy servers with 1,000 mb/s speed – sit back and enjoy your lightning fast private proxies!
99,9% servers uptime
Alive and working proxies all the time – we are taking care of our servers so you can use them without any problems
No usage restrictions
You have freedom to use your proxies with every software, browser or website you want without restrictions
Perfect for SEO
We are 100% friendly with all SEO tasks as well as internet marketing – feel the power with our proxies
Buy more proxies and get better price – we offer various proxy packages with great deals and discounts
We are working 24/7 to bring the best proxy experience for you – we are glad to help and assist you!