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 Studio Chat / [SOLVED] Start and stop animation on sprite the right time during movement start & end

Author
Message
pyx
User Deleted
Posted: 4th May 2020 00:20 Edited at: 4th May 2020 00:22
I have the following problem.
I'm trying to make sprite animated. However, the sprite-animation works, I tested AddSpriteAnimationFrame and SetSpriteAnimation.
However, somehow it doesn't work for me to move the character in a certain direction and playing while this the animation selected frames. I wrote a scrappy code for rapid testing. However, the animation is often triggered when the event (KeyState) already happened
and GetRawKeypressed is as it seems after it got pressed and not while it get pressed. GetLastKey thing also wasn't helpful. Very annoying there is no built-in explanation..

So, I tested different events because GetRawKeyState 1 / 0 returns didn't work. But there are only GetRawkeypressed and keyreleased else there and they also didn't work using the right return-code check.
However, I edited multiple parts of the code again and again for testing, so now it's a bit a mess:

(gets called in do loop)

Btw as you see I try to move sprite without physics so just using SetSpritePosition. Does it even work to play animation DURING position change? As I tried different solutions the animation the result stayed the same.. the animation starts after I released the key.
But doing a if GetRawKeyReleased = 0 within getrawkeystate didnt work. Is this relevant to the reason that the loop & this function is called every 60 frames? Not, right? Unfortunately they didn't show in help how to use different direction animation combined with controls.

The author of this post has marked a post as an answer.

Go to answer

Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 4th May 2020 03:38 Edited at: 4th May 2020 03:40
This post has been marked by the post author as the answer.
you need to check if the proper animation (sequence of frames) is already playing.

if it is, don't restart it (which is what you're doing).

the way you have it set up now, holding the same key down is going to reset the animation to its first frame until keystate = 0.

take a look at this post from conjured and see if that helps?
pyx
User Deleted
Posted: 4th May 2020 12:26 Edited at: 4th May 2020 15:48
Virtual Nomad wrote: "you need to check if the proper animation (sequence of frames) is already playing.

if it is, don't restart it (which is what you're doing).

the way you have it set up now, holding the same key down is going to reset the animation to its first frame until keystate = 0."


Wow I really don't like the way how to do this.
jd_zoo
5
Years of Service
User Offline
Joined: 12th May 2018
Location: Nova Scotia
Posted: 7th May 2020 17:48
Sorry late post to the party.

Quote: "Wow I really don't like the way how to do this."


You can just use if (GetSpritePlaying(Spielerbild) = 0) then PlaySprite ( Spielerbild, 3, 1, 1, 7 ) to check if you already started to play it or not.

Login to post a reply

Server time is: 2024-04-16 20:41:35
Your offset time is: 2024-04-16 20:41:35