[Windows] Gamepad Extension [Now part of Stencyl 3.2+]

thiagojabur

  • Posts: 48
Good evening, lads.

Recently one of our devs (namely tiopalada here on the forums) from our 3 devs team made an extension for those who wanna use a gamepad on Windows. Since I'm the one with access to the forums, he asked me to post it in his behalf. Here are the links:

Extension: https://dl.dropboxusercontent.com/u/12567731/gamepad.rar
Sample game: https://dl.dropboxusercontent.com/u/12567731/WindowsGamepadSample.stencyl

And a short explanation on how it is supposed to be used:

Quote
Hello everybody! Today I've finally took some time to work on a gamepad extension. It is no big deal, since openfl got Joysticks working out of the box, all I did was wrap it up so it become more user friendly.

There is not much use on a joystick extension if it is bind to the developer joystick layout, what the extensions does is allow the dev to place blocks of code in order to read the configs the player desires and bind those configs to game keys. There are 5 blocks for that purpose:

Startup the jostick listeners using %0 sensitivity. - The very first block you must use. It will set up a sensitivity (it only makes sense for analogs and triggers) and startup the basic listeners. After that you will want to read the player input.

Maps control %0 to some joystick input. - As the name says, it will creat a listener that once it gets a joystick input from the player it will bind that input to the %0 control. After that the config listener is removed.

Return a 2d Text List of the mapped controls. - If you wish (and I bet you do) to save the player config you will have to use this block and place that on a List. After that you can save the game. Later you will have to load those values using the next block.

Setup the controls mapping based on %0 2d Text List. - Based on loaded values from the block above you can setup the joystick binds accordingly.

Gets the pressure, if possible, for the control %0. - This one is for those who want the games a bit more responsive. In the sample game you can see that if you have binded an analog to any command the blocky character will either walk or run, depending on how hard you push the analog lever.

Hope you guys enjoy it and make good use of it. :)

If you guys have any questions, PM tiopalada!

« Last Edit: February 03, 2015, 08:35:46 pm by Jon »

DudeMakingAGame

  • Posts: 306
Awesome, thank you very much!

thiagojabur

  • Posts: 48

DudeMakingAGame

  • Posts: 306
Okay, I just updated it and got it working for MAC/Linux, kind of. You can map everything to it except the left analog stick....
If you try to map the left analog stick it will always just move up. Probably something to do with the sensitivity (I was using a wireless 360 controller through http://tattiebogle.net/ driver on MAC. Everything else mapped fine.

In the original extension, you were using nme.events.JoystickEvent. I changed it to openfl.events.JoystickEvent (https://github.com/openfl/openfl-native/blob/master/openfl/events/JoystickEvent.hx) and got MAC/LINUX up and running.
I have to go on a business trip for a couple days but I've attached it here in case anybody wants to clean it up.

Thanks!

thiagojabur

  • Posts: 48
Response from Gabriel/tiopalada:

Quote
Oh, I could swear that the openfl one just pointed out to the nme one. I might double check that because, as far as I can tell, the axes are registered in a different way on that one you've linked. On NME the axes are arranged on a array, every 3 positions on that array reference to one axis (x,y,z) of an specific analog. If I've got it right they've made a padding on the openfl one, which makes things a lot better since I can use bitwise shift operations over them and give some pretty output to the player/dev like "X Axis Left Analog 1". That is quite useful and user-friendly for config menus. Once I get home I will take a look at it, thanks for the input, dude Dude!

DudeMakingAGame

  • Posts: 306
Awesome, I'll have my MAC + controller with me so if you update, I can test for you.

Just to make sure I'm doing the example right: I should hold down the mouse on the direction and then set it with the joystick, then release mouse and that's when it saves it to config. Correct?

DudeMakingAGame

  • Posts: 306
One other quick thing: How are you guys handling more than one controller? Are you getting the id from OPENFL?

thiagojabur

  • Posts: 48
Quote
For example, on the sample game, just click the left arrow (click and release) then press some button/axis/hat. That joystick input will be binded to the left control and the listener to that control mapping will be removed, this way just the first event to arrive is binded. But you can do it again if you're willing to change that config, every time you click one the arrows the mapping listener is created once again (I just noticed that I need to check if there is any other mapping listener, in case the previous one didn't got removed). Once you're done, click OK and those binds will be saved and loaded the next time you run the game.

I totally forgot about multiple devices haha. But that wouldn't be a big of a deal, it is just adding one more value to my String. But I don't have another device here to test :C (and that is why there is no trackball mapping also, I don't have a device with a trackball). Will try to borrow another joystick from a friend.

« Last Edit: January 20, 2014, 01:03:02 pm by thiagojabur »

MidnightRyder

  • Posts: 73
I've got about 90% working Ouya controller implementation - mind if I take a stab at using what you have and integrating into it, rather than releasing a separate extension, then give ya'lls a diff of the two?

DudeMakingAGame

  • Posts: 306
Sure! Just as long as we are using openfl.events.JoystickEvent so we can always pick up any changes they make in OPENFL for basically free.

thiagojabur

  • Posts: 48
Quote
I have a doubt, Dude. Did you get that openfl.events.JoystickEvent from the openfl lib that comes with Stencyl? Because that one you linked differs from the one I have here. Btw, did you got to test the input once again, using the procedure I've described?

DudeMakingAGame

  • Posts: 306
It looks to be the same. Make sure you have the latest version and then in your folder go:
plaf>haxe>lib>openfl-native>1,1,4>openfl>events>JoystickEvents.hx

Just to be clear, openfl-native should be what's used when you build to native clients for MAC and Windows. Which is what I've been testing on. I imagine you are doing the same?

DudeMakingAGame

  • Posts: 306
Also, I did test again and same thing: can't map to left axis. can map every other button perfectly fine. Mapping anything to the axis causes the character to just walk straight up all the time.

thiagojabur

  • Posts: 48
tiopalada here, jabur got tired of posting my answers so he shared his acc info with me haha. And yeah, the fact is that my Stencyl version is older than yours. I'm on a trip atm, but once I'm back home I will take a look at the gamepad once again and see if the same is happening there. I have some clue on what is going on, but I need to confirm it.

DudeMakingAGame

  • Posts: 306
Thanks! Also, check your (his) pm's :)