Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Problems with keyboard movement

Author
Message
ozziedave
17
Years of Service
User Offline
Joined: 20th Apr 2006
Location: Australia
Posted: 19th Aug 2011 02: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
LeeBamber
TGC Lead Developer
24
Years of Service
User Offline
Joined: 21st Jan 2000
Location: England
Posted: 19th Aug 2011 05: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

I drink tea, and in my spare time I write software.
bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
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.
KISTech
16
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
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.

Paul Johnston
TGC Developer
21
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 20th Aug 2011 00: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.
mr_d
DBPro Tool Maker
17
Years of Service
User Offline
Joined: 26th Mar 2007
Location: Somewhere In Australia
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?

Paul Johnston
TGC Developer
21
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 22nd Aug 2011 18:58
Quote: "Have these keyboard scankeys been innately defined"


Only in tier 2

Login to post a reply

Server time is: 2024-04-19 20:49:38
Your offset time is: 2024-04-19 20:49:38