O
Otyugra
Guest
So I have an old controller made specifically for playing games on computers (I suppose Windows computers in particular, considering my computer runs windows) and I've used it before to play Super Crate Box (a game made with GameMaker) and the controller worked fine. When I tried to program the controller input to function identical to a left or right key press, the character does not move when I press left or right on my Dpad. The controller has the same number of buttons for all types as an Xbox 360 control, except a few of the buttons are arranged slightly different.
Here is code that I used in obj_GamePad for Event: System:
ThePad is a global variable, you'll see it again later.
Here is code for the player (obj_Sikk) in event: Step:
Pay little attention to variables like "PressRi" as they are triggers for certain events. The content within a button press or release is the same as for a key press or release.
Thank you for helping.
Here is code that I used in obj_GamePad for Event: System:
Code:
show_debug_message("Event = " + async_load[? "event_type"]);
// Debug code so you can see which event has been...
show_debug_message("Pad = " + string(async_load[? "pad_index"]));
// ...triggered and the pad associated with it.
switch(async_load[? "event_type"])
// Parse the async_load map to see which event has been triggered
{
case "gamepad discovered":
// A game pad has been discovered
AJoystick = true
var pad = async_load[? "pad_index"];
ThePad = pad
// Get the pad index value from the async_load map
gamepad_set_axis_deadzone(pad, 0.5);
// Set the "deadzone" for the axis
gamepad_set_button_threshold(pad, 0.1);
// Set the "threshold" for the triggers
break;
case "gamepad lost":
// Gamepad has been removed or otherwise disabled
AJoystick = false
var pad = async_load[? "pad_index"];
ThePad = pad
// Get the pad index
break;
}
Here is code for the player (obj_Sikk) in event: Step:
Code:
//moving left and right
if gamepad_button_check_pressed(ThePad, gp_padl)
{
sprite_index = spr_SikkD2;
left = 1;
PressLe = 1;
hspeed = 1;
}
if gamepad_button_check_pressed(ThePad, gp_padr)
{
sprite_index = spr_SikkD;
PressRi = 1;
left = 0;
hspeed = 1;
}
//Releasing left or right
if gamepad_button_check_released(ThePad, gp_padl)
{
PressLe = 0;
if PressRi == 0
{
hspeed = 0
sprite_index = spr_SikkA2
}
position_empty(self.x, self.y+1)
{
if vspeed == 0
{
vspeed = 0.5
gravity_direction = 270
gravity = 0.7
}
}
}
if gamepad_button_check_released(ThePad, gp_padr)
{
PressRi = 0;
if PressLe == 0
{
hspeed = 0
sprite_index = spr_SikkA
}
position_empty(x, y+1)
{
if vspeed == 0
{
vspeed = 0.5
gravity_direction = 270
gravity = 0.7
}
}
}
Thank you for helping.