• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Tutorial: Making older gamepads work in GameMaker

F

foldupgames

Guest
Hey guys, I recently got an NES-style gamepad for a work-related project. It doesn't work on the new gamepad functions, but the old joystick commands will make it behave. I wanted to share for future reference.

Those joystick inputs seem a little more limited, but are working! Here's the reference in the GM manul: https://docs.yoyogames.com/source/d... and other controls/joystick input/index.html

One big limitation is that it does not seem to have a "key press" or a "key release" type function, so you'll need to work around it. Your code will have to be more like a button check to see if the button is active. Think of it a "keyboard_check_direct" for everything and you'll get it. Here are a few tips on writing code for it.

1) MAKE SURE WINDOWS SEES IT

You should be seeing it work under your USB Controller settings. This is really helpful because you can also get a read on what it considers to be the button's numbers. It won't tell you the D-Pad's direction number, but it will give you a number for every other button. You'll want that

2) CHECK TO SEE IF GM DETECTS THE GAMEPAD

if joystick_exists(1)

That's the catch-all to use at the start of any gamepad code or if you want to draw something to confirm. Mind you, this can lead to game slowdowns if you have it in a STEP event, so you will do better to create a global variable and have it check it periodically on an alarm somewhere, such as a main control object. If it pings every few seconds, you should be fine.

3) CHECK D-PAD DIRECTIONS

You can have Game Maker draw what it's seeing as Direction Pad inputs with this bit of code:
draw_text(x,y,joystick_direction(id))

For mine:
101=no direction, 100=left, 104=up, 102=right, 98=down, 103=up left, 105=up+right, 97=down+left, 99=down+right

To put it to use, you'd do something like this:
if joystick_direction(id)=102 //pressing right
hspeed=10 //move right

4) CHECK BUTTON PRESSES

Remember up in Step 1 when you checked inputs? Let's put them to use
joystick_check_button(1, 1)

What that means (the pad you're using, the button being pushed)

Example of jump code
if (joystick_check_button(1, 1) or joystick_check_button(1, 2)) //If they press B OR A
vspeed=-10

CONCLUSION

That's all. I hope it helps someone in the future!
 
Top