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 / Animating sprite with keypress

Author
Message
James Tighe
9
Years of Service
User Offline
Joined: 22nd Jul 2015
Location: Portsmouth, Hampshire, UK
Posted: 22nd Jul 2015 23:15
Hi People,

I am a complete newby to AppGameKit and am experiencing some issues with sprite animation.

I am just testing out controlling a sprite with key presses and want the sprite to animate when i do this.

I have a sprite setup with 4 animation frames. I can get it to animate on when one key is pressed but I want to be able to go left, right, up and down with animation.

My code is below



I can see this type of code work with the playermovement project in the examples, but this uses the virtual joystick. Is it not possible to have the animation stop/start on multiple GetRawKeyState commands?

Any help would be appreciated.

Cheers

James
2Beastmode4u
13
Years of Service
User Offline
Joined: 14th Feb 2011
Location: Loading...
Posted: 23rd Jul 2015 01:49
Just to clarify. Are you saying that it plays the same animation with every key or that it only works with one key? If it is the latter please specify which key.
James Tighe
9
Years of Service
User Offline
Joined: 22nd Jul 2015
Location: Portsmouth, Hampshire, UK
Posted: 23rd Jul 2015 10:54
Sorry I will clarify.

If I add the below if loop into the if GetRawKeyState(KEY_LEFT) to determine whether the sprite is playing or not



It will work if added to only the GetRawKeyState(KEY_LEFT) statement. It will work fine and the sprite will animate when the left cursor is pressed and no animation will happen on the other key. This is fine and looks like it is working.

The problem comes when I add the same if loop to the GetRawKeyState(KEY_RIGHT). As soon as I add the if GetSpritePlaying(2) = 0 it stops working on either key.

My question is whether there is something wrong with my logic in the if statements? As far as I can see on each key press it should do a check to see if the sprite is currently playing. If not it should play the sprite.

I hope that explains my problem a little better. I'm sure its probably me not understanding the logic but its slightly annoying
Funnell7
13
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 23rd Jul 2015 11:45 Edited at: 23rd Jul 2015 11:46
Its because you have said in both statements that if the button is NOT pressed then stop the animation. Therefore both statements are conflicting... i.e. if you press Key_Left, the Key_Right statement is hitting the stopsprite(2) condition...

Using AppGameKit V2 Tier 1
James Tighe
9
Years of Service
User Offline
Joined: 22nd Jul 2015
Location: Portsmouth, Hampshire, UK
Posted: 23rd Jul 2015 14:21
I knew it would be me being stupid then . . .

I fixed it by removing the incorrect logic and moving the StopSprite(2) into a separate if loop as below.



This was annoying me for quite a while so thanks very much for the help!

James
Funnell7
13
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 23rd Jul 2015 15:25
Quote: "thanks very much for the help!"


Most welcome, well done for finding the solution

Using AppGameKit V2 Tier 1

Login to post a reply

Server time is: 2024-11-25 19:33:11
Your offset time is: 2024-11-25 19:33:11