Login | Register

Keyboard issue

October 11, 2006, 20:14 by Calle
[loading]
-->
<b>Question:</b> Hello,

here is my problem:

when I press left & right key at the same time, character I am using is facing always right (like the right side always has the initiative). I want to make him face left if I hold the right buton and afterwards press left and face right if I hold the left button and afterwards press right. Is there anyone willing to help?

D&;D or code it doesn't matter, I'm stuck with this problem so I desperatelly need help

Thanks.

<b>Answer:</b> This has to do with Game Maker and how it handles the keyboard. IsmAvatar I remember wrote an excellent script for this purpose, amongst others, but there is also a very simple way of doing this, one which I will show you now:

if (keyboard_lastkey==vk_right) {
sprite_index = spr_right;
}
if (keyboard_lastkey==vk_left) {
sprite_index = spr_left;
}


As you see, it is the variable keyboard_lastkey which does the trick. It indicates which key was last pressed, and if it would be the right key then the code will choose the right sprite, otherwise the left sprite.

Comments

Loading comments... [loading]
.
Users logged in:

game maker articles, game maker examples, game maker tutorials, gmtutorials, game maker questions and answers, game maker crash course, how to create games