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

Keybinds and drawing text in tutorials

Smacktard

Member
I'm wondering if there's an easy way to draw text that displays whichever key is bound to an action. For example, if I allow players to bind "jump" to any key on the keyboard, how could I communicate, during the game's tutorial, which button = jump? Is there any way to draw text that shows the re-bound key? The only way I can think of doing it is through a convoluted DS Map system, and even then I don't really have the details ironed out in my mind.

Example:

Character: Press [BOUND KEY] to jump!

How do I replace "[BOUND KEY]" with whatever key the player has changed it to? Is this even possible without developing some gargantuan, complicated system that would be incredibly difficult to adapt to Russian/Japanese keyboards, for example?
 

poorlocke

Member
This is not a small thing to do. I did it a couple of weeks ago for a game. How I did it:
In the gml_pragma initialization script
- made an global enum with all the input commands e.g. input.jump, input.attack etc
- made a global ds_grid 5 x input enum height
The columns are: input command, keyboard key, gamepad button, keyboard key sprite, gamepad button sprite
- after that I load the ini that has either the user controls or the default controls

In the draw gui event of the camera object
I draw the text and the sprite from the global ds_grid that has the sprites

Changing the inputs is a bit complicated to write here and since I'm on mobile I can't post code. If you would like I can make a video tutorial.
 

Smacktard

Member
Changing the inputs is a bit complicated to write here and since I'm on mobile I can't post code. If you would like I can make a video tutorial.
I think it's pretty clear already from this post alone. But what I'm understanding is that you'd need to draw a sprite of every single keyboard key, for keyboards across multiple languages (such as Russian and Japanese), correct?
 

Smacktard

Member
This is not a small thing to do. I did it a couple of weeks ago for a game. How I did it:
In the gml_pragma initialization script
- made an global enum with all the input commands e.g. input.jump, input.attack etc
- made a global ds_grid 5 x input enum height
The columns are: input command, keyboard key, gamepad button, keyboard key sprite, gamepad button sprite
- after that I load the ini that has either the user controls or the default controls

In the draw gui event of the camera object
I draw the text and the sprite from the global ds_grid that has the sprites

Changing the inputs is a bit complicated to write here and since I'm on mobile I can't post code. If you would like I can make a video tutorial.
So, I think I've figured out how to do the bulk of this -- the only thing I *can't* quite figure out is how to draw the correct sprite in a way that's efficient. The only way I can think is to use a ds_map and assign an array with all of the sprites ahead of time.

Example (for two different keybindings):

GML:
for (i = 0; i < max_keyboard_keys; i++
{
    if (global.KeyBindingList[# 1,(global.KeyBind)]) == i
        {draw_sprite(x-16,y,keybind[i]}

    if (global.KeyBindingList[# 1,(global.KeyBind+1)]) == i
        {draw_sprite(x+16,y,keybind[i]}
}
I'd just need to find out which integer each keyboard key represents. For example, Spacebar is like 32 or 36 or something like this.

Would this work?
 
Last edited:

poorlocke

Member
So, I think I've figured out how to do the bulk of this -- the only thing I *can't* quite figure out is how to draw the correct sprite in a way that's efficient. The only way I can think is to use a ds_map and assign an array with all of the sprites ahead of time.

Example (for two different keybindings):

GML:
for (i = 0; i < max_keyboard_keys; i++
{
    if (global.KeyBindingList[# 1,(global.KeyBind)]) == i
        {draw_sprite(x-16,y,keybind[i]}

    if (global.KeyBindingList[# 1,(global.KeyBind+1)]) == i
        {draw_sprite(x+16,y,keybind[i]}
}
I'd just need to find out which integer each keyboard key represents. For example, Spacebar is like 32 or 36 or something like this.

Would this work?
Yeah sorry, I was working on some shaders and didn't have the time to do the video. The way I do it is by referencing the grid cell that holds the sprite. Either way you can do it with any data structure you want
 
Top