SOLVED how do i install virtual keys?

R

rgamer

Guest
how do i install virtual keys?
 
Last edited by a moderator:
R

rgamer

Guest
I've seen several tutorials on how to install as virtual keys, but I'm not getting it. Could someone explain to me how to install and place as steps (step by step) and conclude: why run the buttons to walk left and right, jump and shoot? I appreciate the collaboration.
 

chamaeleon

Member
I've seen several tutorials on how to install as virtual keys, but I'm not getting it. Could someone explain to me how to install and place as steps (step by step) and conclude: why run the buttons to walk left and right, jump and shoot? I appreciate the collaboration.
If you make a call to virtual_key_add, you designate a rectangle on the screen to simulate a key press (you provide which key press is determined by the last argument). If you have an event that reacts to that key press, if you touch the screen in that rectangular location, the program will respond as if you have pressed the equivalent key on a keyboard. The step-by-step is to make that one function call. Done. If you have problems with that to do reacting to input events in general, you should say so, and perhaps start a new topic with specific questions
 

FrostyCat

Redemption Seeker
Why waste time on tutorials when the Manual's instructions tell you exactly what virtual keys do and what needs to be done?

Assume you have a 1920x1080 screen, and you want virtual keys at these positions:
  • Left (left arrow): (0, 920), 160x160
  • Right (right arrow): (1760, 920), 160x160
  • Shoot (space bar): (1760, 760), 160x160
Create a controller object and put this in its Create event to set up the keys:
GML:
leftVk = virtual_key_add(0, 920, 160, 160, vk_left);
rightVk = virtual_key_add(1760, 920, 160, 160, vk_right);
shootVk = virtual_key_add(1760, 760, 160, 160, vk_space);
And this in its Cleanup event to remove the keys when it is done:
GML:
virtual_key_delete(leftVk);
virtual_key_delete(rightVk);
virtual_key_delete(shootVk);
And if applicable, draw the buttons' locations in the Draw GUI event. Here is a rough example:
GML:
// Left and right virtual keys
draw_set_colour(c_blue);
draw_rectangle(0, 920, 160, 1080, false);
draw_rectangle(1760, 920, 1920, 1080, false);
// Shoot virtual key
draw_set_colour(c_red);
draw_rectangle(1760, 760, 1920, 920, false);

// Text labels
draw_set_colour(c_black);
draw_text(0, 920, "Left");
draw_text(1760, 920, "Right");
draw_text(1760, 760, "Shoot");
Then pressing these areas on a touch device's screen will have the same effect as pressing the corresponding keys on a keyboard-enabled device.
 
Top