How do I use special characters with Sprite Fonts?

Get help using Construct 2

Post » Wed Feb 08, 2017 2:32 pm

Hi,

I am working in the key binding menu and I use a custom sprite font to display the actual bound keys. My question is:

Is there a way to put keys like 'left arrow', 'right arrow', 'space bar' etc in the character set?
B
6
S
2
Posts: 61
Reputation: 1,099

Post » Wed Feb 08, 2017 2:52 pm

SpriteFont just maps keys to a grid position in the PNG file. Just add some extra characters that you won't use and edit those characters in the PNG to change the graphic to something else (left-arrow...). Since you are mapping keyboard-keys, presumably you are mapping capital letters, so you could use lowercase letters to map to your special keys.
ImageImageImage
B
71
S
22
G
241
Posts: 3,734
Reputation: 134,494

Post » Wed Feb 08, 2017 2:57 pm

blackhornet wrote:SpriteFont just maps keys to a grid position in the PNG file. Just add some extra characters that you won't use and edit those characters in the PNG to change the graphic to something else (left-arrow...). Since you are mapping keyboard-keys, presumably you are mapping capital letters, so you could use lowercase letters to map to your special keys.



But to display the letter I use 'Keyboard.StringFromKeyCode(key)', and they keycode of the bound key will not correspond with the 'Left arrow', for example. Am I right?
B
6
S
2
Posts: 61
Reputation: 1,099

Post » Wed Feb 08, 2017 3:19 pm

I didn't realize the arrow keys do actually have characters,←→↑↓, so there is no problem there. See what string comes back from each key and use that, as long as it is only a single character.
ImageImageImage
B
71
S
22
G
241
Posts: 3,734
Reputation: 134,494

Post » Wed Feb 08, 2017 3:27 pm

font
Image

Image

Image

seem to work

Image
B
66
S
24
G
7
Posts: 1,514
Reputation: 11,039

Post » Wed Feb 08, 2017 3:29 pm

@korbaach @blackhornet Nice, but how did you write that characters? Maybe a stupid question, but I don't know how u did it.

And also I need 'Ctrl', 'Alt', Shift...

Thanks, and sorry for too many questions
B
6
S
2
Posts: 61
Reputation: 1,099

Post » Wed Feb 08, 2017 3:35 pm

I just logged the text to the console and copied it. I don't know how to generate the actual characters from the keyboard. For control, alt, etc., they return strings, not characters, so you are going to have to search for those strings first, and convert to some special character that can be mapped in SpriteFont. 'Shift' is not reported as a key code.
ImageImageImage
B
71
S
22
G
241
Posts: 3,734
Reputation: 134,494

Post » Wed Feb 08, 2017 3:39 pm

blackhornet wrote:I just logged the text to the console and copied it. I don't know how to generate the actual characters from the keyboard. For control, alt, etc., they return strings, not characters, so you are going to have to search for those strings first, and convert to some special character that can be mapped in SpriteFont. 'Shift' is not reported as a key code.


Ok mate, thank you very much! :D
B
6
S
2
Posts: 61
Reputation: 1,099

Post » Wed Feb 08, 2017 3:49 pm

B
66
S
24
G
7
Posts: 1,514
Reputation: 11,039


Return to How do I....?

Who is online

Users browsing this forum: PROxMTswatTR and 17 guests