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 / walking animated sprite

Author
Message
cryptojoe
12
Years of Service
User Offline
Joined: 27th Sep 2012
Location: Michigan U.S.A
Posted: 31st Dec 2012 05:34 Edited at: 31st Dec 2012 18:29
ok so I'v ben working on this all day and can not come up with a working solution...I have a realy nice animated sprite that I want to make walk across the screen useing user input...I want the sprite to be animated when moveing and not when not moveing... I have tryed every thing I can think of and the best results I get are 1 animated cycle plays after the sprite has moved "often some distance depending on how long the arrow key was held down...

PLEASE HELP

*EDIT
code fixed and running better than I dreamed...
thank you Hodgey,Hockeykid and Simpleprogram...
code updated for anyone who wants to see it...

SimpleProgram
13
Years of Service
User Offline
Joined: 2nd Oct 2011
Location: Cali
Posted: 31st Dec 2012 06:11 Edited at: 31st Dec 2012 06:19
This might help:

First get rid of the extra first playsprite() command, its really not needed since you will be playing the sprite later.

put this outside of the loop:



then add this in the loop instead of what you have for moving the sprite:





This code should move the sprite in either direction, flip it, and stop it from moving when necessary.

Programming and video games, what else could you need?
cryptojoe
12
Years of Service
User Offline
Joined: 27th Sep 2012
Location: Michigan U.S.A
Posted: 31st Dec 2012 07:00
ok it runs, but I'm getting a 1 sprite while moveing and a flickering sprite when stoped "I think its running to many fps" that moves in the opposite direction of the arrow key pressed...

but I think your on the right track...
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 31st Dec 2012 07:08
With your original code cryptojoe, every time you call PlaySprite, it restarts the animation, and as you're continuously calling it according to the IF statement, you're continuously resetting its animation. A quick fix might be to check the current frame and only reset it when the current frame is equal to 6. E.g



Hockeykid
DBPro Tool Maker
17
Years of Service
User Offline
Joined: 26th Sep 2007
Location:
Posted: 31st Dec 2012 07:34 Edited at: 31st Dec 2012 07:37
This should also work:



The solution is to loop the animation while the sprite is moving (but only if it isn't already looping) and stopping the animation when the sprite stops moving.


Sean

cryptojoe
12
Years of Service
User Offline
Joined: 27th Sep 2012
Location: Michigan U.S.A
Posted: 31st Dec 2012 07:43
thats got it Hodgey... I thank you very much...

thank you all, I'm going to get some sleep....
cryptojoe
12
Years of Service
User Offline
Joined: 27th Sep 2012
Location: Michigan U.S.A
Posted: 31st Dec 2012 16:37 Edited at: 31st Dec 2012 18:35
Hockeykid, your code runs great as well... I will be keeping a copy of each for future reference...

*EDIT
I think I can add the command setspriteflip that simpleprogram showed me... and a few more lines of code and have my sprite walking both ways...

*EDIT
sprite now walks both ways... I'm realy looking forward to showing this working Demo off to my friends at the party tonight thanks to you guys... oh and the code at the top has ben updated...

Login to post a reply

Server time is: 2024-11-24 06:37:01
Your offset time is: 2024-11-24 06:37:01