• 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!

Checking if More Than One Key is Being Pressed

T

Tonydaderp

Guest
I've been trying to do something. If you guys could tell me how to checking if More Than One Key is Being pressed.. It'd be greatly appreciated. maybe I can use keyboard_check_direct? Thanks.
 

Nux

GameMaker Staff
GameMaker Dev.
Code:
 if Keyboard_check(ord("A")) and Keyboard_check(ord("B"))
{
    // do code
}
This will check if keys A and B are held down. And if they are then perform the code nested within
 
T

Tonydaderp

Guest
No... I already knew that, but thanks! What I wanted was the Zelda like diagonal movement. When you move up and press right, your sprite changes into the up sprite still.
 

Nux

GameMaker Staff
GameMaker Dev.
ah that's pretty simple, you can add priority to your keys. The simplest way to do this is:
Code:
if keyboard_check(vk_up)
{
    // up sprite
}
else if keyboard_check(vk_down) // up and down have most priority
{
    // down sprite
}
else if keyboard_check(vk_left)
{
    // left sprite
}
else if keyboard_check(vk_right)
{
    // right sprite
}
 

TheouAegis

Member
if left or right
if vspeed==0
sprite_index = left or right sprite​
if up or down
if hspeed==0
sprite_index = up or down sprite​
 
R

renex

Guest
I typically do this with temporaries.

h = right-left
v = down-up

then you can get the movement direction from a point_direction(0,0,h,v) and poll h and v separately for the sprite properties.
 
Top