Gamepad keycodes/bindings mess

0 favourites
  • 6 posts
From the Asset Store
Total customisation of the input! You can combine inputs from all peripherals. Make your game accessible for everyone!
  • Tagging Ashley because he probably knows the most about this but if you have experience with C2's gamepad object I'd appreciate any input (pun intended).

    So...I've set up configurable controls for both keyboard and gamepad, using keycodes and such. Pretty cool. It's all saved to a dictionary and I even consolidated keyboard/gamepad inputs to prevent input condition conflicts in a given event.

    Anyway, problem is...how am I supposed to set the default configuration when all gamepads use different key codes? I thought all controllers modeled after the xbox 360 one used the same keycodes, but apparently that's not the case. I've read they change with OS, too.

    I've been using this for reference...but it's incorrect for all of my gamepads.

    And I also found this from microsoft but it's using bitmasks..so..er...

    I found this while looking through the gamepad.runtime file

    	// How to write a mapping:
    	// Construct 2 normalises all controller states to the format used by the XBox 360 controller
    	// on Chrome/Windows.  Everything is mapped to a single 20-element array in the format:
    	// 0: A								10: Left analog button
    	// 1: B								11: Right analog button
    	// 2: X								12: D-pad up
    	// 3: Y								13: D-pad down
    	// 4: Left shoulder button			14: D-pad left
    	// 5: Right shoulder button			15: D-pad right
    	// 6: Left shoulder trigger			16: Left analog X axis
    	// 7: Right shoulder trigger		17: Left analog Y axis
    	// 8: Back							18: Right analog X axis
    	// 9: Start							19: Right analog Y axis
    	// Since different controllers return buttons and axes in a different order on different
    	// browsers and OSs, all combinations need to be mapped to the above 20-element array,
    	// called the 'c2state'.
    	// The buttons mapping array translates a raw button input to the c2state, and the axis
    	// mapping array translates a raw axis input to the range 0, 1, 2 or 3 (automatically offset
    	// by 16 to fit in to the c2state).  However, sometimes an axis is mapped to a pair of buttons,
    	// e.g. for the D-pad coming up as an axis.  In this case the mapping is another array
    	// of the buttons to map the axis to; the first element for the button when axis negative,
    	// and the second element for the button when the axis positive.  e.g. XBox 360 on Firefox/Windows
    	// has axis 5 mapped to D-pad left and right; the entry is [14, 15] to map negative (left) to
    	// c2state 14 (D-pad left), and positive (right) to c2state 15 (D-pad right).
    	// If no mapping exists for an OS/browser/controller configuration, it defaults to assuming it's
    	// the same as Windows/Chrome/XBox 360, done by the defaultMap function.[/code:2kai9r9d]
    
    Do I need to do something similar? So confused -w-;
    
    For the record I'm only using NWjs. Controllers tested are MadCatz 360 Controller, Logitech 360 controller, WiiU pro controller. I also have a PS2 controller but I haven't tested it yet. IIRC C2 didn't even recognize it when I tried long ago.
  • In theory the browser should do key mapping, but last I tested it (a long time ago) there were still differences between Firefox, Chrome, Windows/OS X etc. so C2 does some mapping in the plugin itself. There's not really any good solution to this though since whoever is supposed to fix this (you, us, browsers, OSs, gamepad manufacturers) faces the problem of normalising gamepad keys across probably hundreds of models of gamepad, which is pretty hard work. So I'd just test across any major models of gamepad you can find and if the mapping doesn't work out try to correct it.

  • So Tokinsom what did you do to solve the issue ?

    Just asking out of curiosity since we've been thinking about adding controller support & a way for the Player to set own keybinds.

    So far I've found this topic but doing it like EpicPixel said might give me problems because of some conditions used

    Also found this one but don't know if I can use it for gamepads as well

    For now guess I'll just test some stuff out and play with it a bit to see if it works like I have in mind, and else no gamepad or only 1 setup for it

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Ataraxis Well, there's no way to reliably predict a gamepad's key codes so I set them all to 99 by default and have the player configure the gamepad before use. Not a big deal, really. I don't recall any indie games that had "plug and play" gamepad support anyway, so eh.

  • Thanks for the fast reply, was talking to my friend about it and we were thinking about doing the same, but were not sure if it might mess with something else. Good to know it can really be that simple ^^.

  • hi guys..can u help me ? is there a capx to understand how to customize a gamepad ? thanks

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)