• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Check if using either gamepad or keyboard

T

TheRBZ

Guest
Hello, I want to fix an issue that I have overcome when making controller support for my game. Moving the player object work fine enough, but I have doors that check for collision, and if there is, they change sprite. But the two sprites I have are spr_door (normal door), spr_door_down (door with down arrow above) and spr_door_y (door with Y button above it.

my code is:
For obj_processes_Step_1:
Code:
if (gamepad_button_check_pressed(0,i))
{
using_gp = 1;
using_kb = 0;
exit;
}
else
if keyboard_check(i)
{
using_gp = 0;
using_kb = 1;
exit;
}
this *tries* to figure out if ANY button on keyboard or gamepad are pressed.

For obj_door_Step_1:
Code:
if (place_meeting(x, y, obj_player)) {
   if using_gp = 1{
   sprite_index = spr_door_Y;
   if (gamepad_button_check_pressed(0,gp_face4)){
      room_goto(rm_1_1);
      }
   }
   else
   {
        sprite_index = spr_door_down;
        if keyboard_check(vk_down){
        room_goto(rm_1_1);
        }
   }
}
else {
   sprite_index = spr_door;
}
Basically, I want the door to change sprite accordingly to what controller type (kb or GP) is being used.
e.g. I'm using kb, when I collide with obj_door, change obj_door sprite to spr_door_down.
 
D

dj_midknight

Guest
If I may suggest have the opening screen determine which is being used.
What I mean by this is do something along the lines of a popup that says "press space or A to continue"
Based on whether the player presses the space bar or the A button will set the flag for the remainder of the game.
 
T

TheRBZ

Guest
ok. Just how though? I have tried before, but gotten errors. Lots of them.
 
D

dj_midknight

Guest
Use your splash screen to set a global variable. Something along the lines of global.control_type = 0;
control_type == 0 = not set
control_type == 1 = keyboard
control_type == 2 = gamepad

Then at your menu screen step event do something like
Code:
if(keyboard_check_pressed(vk_space)){
    global.control_type = 1;
    room_goto(first_room);
}
else if(gamepad_button_pressed(0, gp_face1)){
    global.control_type = 2;
    room_goto(first_room);
}
then in your door code you do
Code:
if(place_meeting(x,y,obj_player){
    if(global.control_type == 1){
         //keyboard code goes here
    }
    else if(global.control_type == 2){
        //gamepad code goes in here
    }
}
else{
    //default code here
}
Alternately you can do what alot of us do and just make the buttons universal and describe the function that causes it.

Ex: Jump = keyboard_check_pressed(vk_space) || gamepad_button_pressed(0, gp_face1);
Interact = keyboard_check_pressed(ord("W")) || gamepad_button_pressed(0, gp_face2);

Then you basically tell the player to press the jump button and they should already know what to do based on their controler choice.
 
Last edited by a moderator:
T

TheRBZ

Guest
thankyou. It works. It would be better for it to check every step live for what I'm using, but I tried that and It didn't work.
 
Top