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.

Newcomers AppGameKit Corner / PlaySprite And Animation

Author
Message
GreenDixy
14
Years of Service
User Offline
Joined: 24th Jul 2008
Location: Toronto
Posted: 5th Oct 2022 00:14
Having problems with keystates and animations
when i comment out the PlaySprite (sprite, 0, 1, 1, 1 ) line in the = 0 keystates the animation works
otherwise it does not... it tries to play but does a slight jitter movement
any help is greatly appreciated

fubarpk
Retired Moderator
18
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 5th Oct 2022 09:59
its a good idea to check that the sprite animation has stopped playing with GetSpritePlaying(spr) before initiating a new play command
you could use StopSprite( Spr) but depending on the rest of code that may help.
PK
Virtual Nomad
Moderator
17
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 5th Oct 2022 10:27 Edited at: 5th Oct 2022 10:34
you have conflicting and/or redundant statements.

if neither A nor D is pressed, PlaySprite ( sprite, 0, 1, 1, 1 )

if A is pressed then PlaySprite (sprite, 21, 1, 2, 21 ) but if D is NOT pressed at the same time, PlaySprite ( sprite, 0, 1, 1, 1 )
ie, PlaySprite (sprite, 21, 1, 2, 21 ) will never happen since you later tell it to PlaySprite ( sprite, 0, 1, 1, 1 ) in the loop

then, if A is pressed, PlaySprite (sprite, 21, 1, 2, 21 ) but if D is also pressed, PlaySprite ( sprite, 23, 1, 1, 23 ) will occur since you told it to last

you're also telling (each) to start respective animation sequences from their first frame if a key is or isn't pressed, over and over. i can't remember but i don't think you'll ever see the second frame until a key is released (and/or NOT released...).

in the end, that's not the way to go about things. the logic "isn't"

an example of smoother transitions from one animation to another can be found HERE.

it's using a virtual joystick and a little more advanced than what you're attempting to do but if you study the code you'll see a kind of "logic" that you should be applying where each potential condition is properly accounted for. various "states", if you will.

you'll also pick up some other tips in that code which i think every newcomer should review so it's a good place to start for this kind of thing.

do study it, step by step. and follow where each state or condition leads you. there are a couple things going on at the same time so it's a good exercise IMHO.

meanwhile, welcome
GreenDixy
14
Years of Service
User Offline
Joined: 24th Jul 2008
Location: Toronto
Posted: 6th Oct 2022 07:54
thank you for the advice fubarpk and nomad

Login to post a reply

Server time is: 2023-02-05 19:43:08
Your offset time is: 2023-02-05 19:43:08