Jump to content


Photo

Gamepad Extended - Version 1.1


  • Please log in to reply
49 replies to this topic

#1 Tahnok

Tahnok

    Friendly Madman

  • GMC Member
  • 1730 posts
  • Version:Unknown

Posted 01 June 2008 - 12:18 PM

I finally got tired enough of some of the limitations of GM's built-in gamepad support, so I created this extension. It has the following features:
  • Able to check if a button was pressed or released
  • Analog inputs and POV controls act as buttons, with adjustable dead zone, so all inputs can be handled with the same code
  • Checks whether a joystick exists before attempting to check it's state, since checking non-existent gamepads will slow games down
  • Supports two joysticks
  • Can automatically disable buttons that are being pressed on setup, so they don't interfere with other checks
  • Can suspend the game until a gamepad input is pressed, or until all are released
  • Can automatically find a pressed button on the gamepad
  • Replaces a few other basic functions, but checks whether the gamepad exists first
Download Gamepad Extended

Read the extension's help file for details on how to use it. Also be sure to check out the example, as it demonstrates many of the functions.

Enjoy,
Tahnok

Edited by Tahnok, 02 June 2008 - 04:17 AM.

  • 1

#2 Reshure

Reshure

    Reshure

  • New Member
  • 320 posts

Posted 01 June 2008 - 04:51 PM

Awesome! This is exactly what I need.

Thank you very much!
  • 0

#3 Tahnok

Tahnok

    Friendly Madman

  • GMC Member
  • 1730 posts
  • Version:Unknown

Posted 02 June 2008 - 04:16 AM

OK, I played around with this extension a little more today and found a couple bugs. Apparently, it's possible for the gamepad to change it's state mid-step, which was sometimes causing issues with the press and release functions. I've updated it to now poll all the inputs at the start of the step, so things are a little more predictable.

I also fixed a dead zone issue with the second controller and changed some things around so that updates are now done automatically (though, now you have to manually call the initialization script). See the help file for a full list of fixes/updates. The main link has been updated.
  • 0

#4 IsmAvatar

IsmAvatar

    Good Samaritan

  • GMC Member
  • 2411 posts
  • Version:GM8

Posted 02 June 2008 - 05:08 AM

For a second, I almost thought someone had finally extended upon my GameMaker Notepad (GamePad), but no. lol.

Looks promising, although I wouldn't have much of a use for it.
  • 0

#5 Reshure

Reshure

    Reshure

  • New Member
  • 320 posts

Posted 02 June 2008 - 01:54 PM

I wanted to say thanks again!

It works perfectly :blink:
  • 0

#6 agustusx

agustusx

    GMC Member

  • New Member
  • 27 posts

Posted 04 June 2008 - 12:41 AM

Thanks a lot this helped me out a great deal :P I can finally used my crusty old sidewiders POV as directional control, same for my 360 controller.

Again thanks for sharing.
  • 0

#7 8-BitTonberry

8-BitTonberry

    GMC Member

  • GMC Member
  • 557 posts
  • Version:GM8.1

Posted 13 June 2008 - 02:48 PM

Hey, I'm wondering if there is anyway to return the analogs direction in degrees.

Is this possible to do with this extension or at all?

Ex: Aiming a turret in the direction you're holding.
  • 0

#8 Chaos In a Can

Chaos In a Can

    GMC Member

  • New Member
  • 70 posts

Posted 13 June 2008 - 03:40 PM

Hey, I'm wondering if there is anyway to return the analogs direction in degrees.

Is this possible to do with this extension or at all?

Ex: Aiming a turret in the direction you're holding.



Use point_direction() on the x,y position of the joystick.
//Try this:
direction = point_direction(0, 0, joystick_xpos(1), joystick_ypos(1));

//...or if that doesn't work, try this:
direction = point_direction(0, 0, joystick_xpos(1), -joystick_ypos(1));

  • 0

#9 8-BitTonberry

8-BitTonberry

    GMC Member

  • GMC Member
  • 557 posts
  • Version:GM8.1

Posted 13 June 2008 - 04:10 PM

Sweet! That worked perfectly!

Is there any way to check how far the joystick is actually being pressed?
I know it probably says that in the help, but I can't find it.

And one final thing...

Since each joystick is considered 4 buttons(13, 14, 15, 16 in this case), is there any way to check if it is being pressed at all without checking all of those?

Thanks again!
  • 0

#10 Tahnok

Tahnok

    Friendly Madman

  • GMC Member
  • 1730 posts
  • Version:Unknown

Posted 13 June 2008 - 09:53 PM

Sweet! That worked perfectly!

Is there any way to check how far the joystick is actually being pressed?
I know it probably says that in the help, but I can't find it.

And one final thing...

Since each joystick is considered 4 buttons(13, 14, 15, 16 in this case), is there any way to check if it is being pressed at all without checking all of those?

Thanks again!

GM can natively check how far you're pressing a specific direction. Look in the help manual under GML > User Interaction > The Joystick. You will find functions such as joystick_xpos(id) and joystick_ypos(id), which return between -1 and 1 (0 being centered, most of the time).

No, you have to check each input individually. I suppose I could add a function eventually to check whether all analog stick are released or if any are pressed, but that would kind of defeat the purpose of this extension (making all gamepad code universal, no matter what types of controls a gamepad may have).
  • 0

#11 Warmachine

Warmachine

    GMC Member

  • GMC Member
  • 97 posts

Posted 15 June 2008 - 10:09 PM

Would this actually work with the Xbox360 Pad? I know that some other example shows rumble support etc.
  • 0

#12 Tahnok

Tahnok

    Friendly Madman

  • GMC Member
  • 1730 posts
  • Version:Unknown

Posted 16 June 2008 - 06:34 AM

Would this actually work with the Xbox360 Pad? I know that some other example shows rumble support etc.

If you install drivers for the Xbox 360 gamepad to turn it into a normal windows direct input pad then it should. As far as I know though, it wont work out of the box without the drivers (which is why Sinaz created his extension, which I believe supports it regardless of drivers).

This doesn't have any sort of rumble support, especially for the 360 gamepad. That would require a dll, and this extension is just a wrapper for GM's internal functions to make them easier to use. Sindarin has made the only working force feedback dll for direct input pads and I believe Sinaz's dll supports rumble for the 360 gamepad.

BTW, I don't own a 360 controller to test with.
  • 0

#13 mory

mory

    GMC Member

  • New Member
  • 26 posts

Posted 19 June 2008 - 03:05 PM

well done. tnx

I need somthing Important. Vibration

could you ?
  • 0

#14 Tahnok

Tahnok

    Friendly Madman

  • GMC Member
  • 1730 posts
  • Version:Unknown

Posted 20 June 2008 - 05:22 AM

well done. tnx

I need somthing Important. Vibration

could you ?

No, I can't, but that doesn't matter, someone already has:

http://gmc.yoyogames...howtopic=379111

I was going to put his dll into an extension, but ran into some issues and haven't had a chance to look at it again. It's a fairly easy dll to use though.
  • 0

#15 mory

mory

    GMC Member

  • New Member
  • 26 posts

Posted 29 June 2008 - 02:03 PM

well done. tnx

I need somthing Important. Vibration

could you ?

No, I can't, but that doesn't matter, someone already has:

http://gmc.yoyogames...howtopic=379111

I was going to put his dll into an extension, but ran into some issues and haven't had a chance to look at it again. It's a fairly easy dll to use though.


  • 0

#16 bradshaw

bradshaw

    GMC Member

  • GMC Member
  • 44 posts

Posted 07 July 2008 - 12:43 AM

well done. tnx

I need somthing Important. Vibration

could you ?

No, I can't, but that doesn't matter, someone already has:

http://gmc.yoyogames...howtopic=379111

I was going to put his dll into an extension, but ran into some issues and haven't had a chance to look at it again. It's a fairly easy dll to use though.



Thanks. Perfect.
  • 0

#17 justin123

justin123

    GMC Member

  • New Member
  • 124 posts

Posted 24 July 2008 - 04:29 PM

gamepad_check_button_pressed() doesn't seem to work.
  • 0

#18 Tahnok

Tahnok

    Friendly Madman

  • GMC Member
  • 1730 posts
  • Version:Unknown

Posted 24 July 2008 - 09:26 PM

gamepad_check_button_pressed() doesn't seem to work.

Read the help file. There are two reasons listed in there that could be causing the problem. gamepad_init() has to be called before any other function. Also, make sure any objects calling the press and release checks have a depth between -10,000,000 and 10,000,000.
  • 0

#19 justin123

justin123

    GMC Member

  • New Member
  • 124 posts

Posted 24 July 2008 - 10:45 PM

gamepad_check_button_pressed() doesn't seem to work.

Read the help file. There are two reasons listed in there that could be causing the problem. gamepad_init() has to be called before any other function. Also, make sure any objects calling the press and release checks have a depth between -10,000,000 and 10,000,000.


I still can't get it to work, but i'll give you that part of the code I used:

The create event in objSetup - depth=0
//Declare Variablesgamepad_init()global.button_a_pressed=0;global.button_b_pressed=0;global.button_x_pressed=0;global.button_y_pressed=0;global.button_action_pressed=0;

Now the step event for the same object
global.button_a_pressed=gamepad_check_button_pressed(1,2);global.button_b_pressed=gamepad_check_button_pressed(1,3);global.button_x_pressed=gamepad_check_button_pressed(1,4);global.button_y_pressed=gamepad_check_button_pressed(1,1);global.button_action_pressed=gamepad_check_button_pressed(1,9);

This is what's in the object using those variables. Its depth is also equal to zero.
key_action_pressed  =   global.button_b_pressed;//I used the same variables for gamepad and keyboard.

Note that the keyboard and gamepads are not used at the same time. global.input_config="gamepad" or ="keyboard".
All of the button_pressed functions are always equal to zero for some reason.

Edited by justin123, 24 July 2008 - 10:49 PM.

  • 0

#20 Tahnok

Tahnok

    Friendly Madman

  • GMC Member
  • 1730 posts
  • Version:Unknown

Posted 24 July 2008 - 11:17 PM

I just tried it and it seems to be working just fine. Are you sure you're not just missing the incredibly short press of the button? Try putting this line after that last line of code you gave me:

if(key_action_pressed = true) { show_message("button pressed"); }

If that shows a message then the code is working just fine.

Are you sure you're not mistaking gamepad_check_button_pressed() for gamepad_check_button()? Just like GM's mouse functions, the former will only return true only when the button is pressed down the first time (for a single frame). The latter will return true the whole time the button is held.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users