Posted: 19th Aug 2011 2:59
Hi all,

I am starting a project and am having problems with sprite movements using the keyboard.

My human sprite has a left walking movement and a right one
6 each way on a sprite sheet.

I can get it moving Left & Right, but I want to limit the animation
when no left and right arrows are not being pressed, but in the code below I get no animation at all.

What am I doing wrong, any idea's please.

// check for Left Arrow input
Lkey=GetRawKeyPressed(37) ` Left arrow
if Lkey=1 then
PlaySprite ( Pirate_Sprite, 10, 1, 1, 6 ) //6 animations Left
Pirate_Direction = 1


// check for Right Arrow input
Rkey=GetRawKeyPressed(39) ` Right arrow
if Rkey=1 then
PlaySprite ( Pirate_Sprite, 10, 1, 7, 12 ) //6 animations Right
Pirate_Direction = 2


Lkey=GetRawKeyPressed(37) ` Left arrow
Rkey=GetRawKeyPressed(39) ` Right arrow
if (Lkey=0 and Rkey=0) and (Pirate_Direction = 1) then
PlaySprite ( Pirate_Sprite, 10, 1, 1, 3 )


Lkey=GetRawKeyPressed(37) ` Left arrow
Rkey=GetRawKeyPressed(39) ` Right arrow
if (Lkey=0 and Rkey=0) and Pirate_Direction = 2 then
PlaySprite ( Pirate_Sprite, 10, 1, 7, 9 )

Many Thanks
Posted: 19th Aug 2011 5:42
Be aware that when you use the GetRaw commands, your app will NOT be universally compatible with all the other devices out there (only those with keyboards with the same scan code mapping as yours). I would always advise taking your input commands from the Universal Command Set. For controlling a chappy on the screen, I recommend using the GetJoystick commands, as they will allow you to use W,A,S,D for directional control, joystick/controller if available and AppGameKit will create a virtual joystick on devices that have a touch screen. Using universal commands means you reach everybody who has one of the AppGameKit supported platforms. I plan to create video on the evils of the raw commands as a pre-emptive strike against TGC Mike's video on how great raw commands are. Soon to be followed by the evils of SetVirtualResolution video
Posted: 19th Aug 2011 14:11
RAW commands are necessary. Some people might want to build an iOS specific app (for example) and don't care about other platforms, so they want as many iOS commands available as possible.
Posted: 19th Aug 2011 20:22
Keyboards are really only going to be available on Windows, Mac, and MeeGo platforms. So you can do a check to see what the device is and enable/disable the appropriate input method.

Lee makes a good point about the keyboard scancodes though.

One solution might be to have the user press the keys they want to use for specific actions, and capture those scancodes.
Posted: 20th Aug 2011 0:25
Scancodes will be the same for matching keys across all platforms, at least I've made an attempt to translate them to the same values. Any codes not listed in the help file are probably not cross platform consistent.
Posted: 21st Aug 2011 19:37
I'm using Windows. The help (scancodes.htm) indicates that the scan codes have been defined, e.g. AGK_KEY_ESCAPE as 27, but when I try to use the constant, it doesn't know the value, and registers it to be 0. If I use #constant to manually define AGK_KEY_ESCAPE to be 27, then the raw commands (I'm using GetRawKeyState) work. Have these keyboard scankeys been innately defined or not - or what am I missing?
Posted: 22nd Aug 2011 18:58
Have these keyboard scankeys been innately defined


Only in tier 2