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 DBPro Corner / Animated sprite help?

Author
Message
Don3784
10
Years of Service
User Offline
Joined: 15th Apr 2013
Location:
Posted: 8th May 2013 04:21
ok i am tring to use my animated sword swing to play through once but when the key is pressed it plays constantly so i tried sepreating the key press code from the animation code it helped somewhat but for the life of me i can't figure out a good code to stop the animation when it completes. i don't want the sword to swing again till the key is released and then pressed again.
here is my code
IF pressed = 0
`restarts the sword animation to 1 after space is pressed
IF SPRITE FRAME(16) < 1: SET SPRITE FRAME 16, 1: ENDIF
play sprite 16, 1, 1, 50
endif
elapsed2=(Timer()-t2)
if spacekey()=1 then pressed = 1

if pressed=1 and (move = 3 or move = 5) and attack = 0 and elasped2 < 50

show sprite 16
show sprite 17
hide sprite 14
play sprite 17, 1, 1, 50
`sword animation
play sprite 16, 1, 5, 10

move = 5

t2 = timer()
pressed = 0

elasped2=0

endif]

sorry if it is a bit jumbled i planned to clean it up once it was finished
Chris Tate
DBPro Master
15
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 8th May 2013 12:38
Quote: "key is released"


Code the way you say it.


Don3784
10
Years of Service
User Offline
Joined: 15th Apr 2013
Location:
Posted: 8th May 2013 17:25
thank you for the quick response chris tate
that is helpfull code to tell when the key is relased but my major issue is i need the animation to only cycle once and to cycle to the end no matter what the keystate is at the time.

I do appreciate that key released code though that will help me with some stuff later
Don3784
10
Years of Service
User Offline
Joined: 15th Apr 2013
Location:
Posted: 8th May 2013 22:59
ok i finally got it so i will post it in case someone else has a similar problem and didn't get the answer this does include Chris Tate's key released code so you will have to use his function example above to work it in this way.
One lingering problem is my character sprite flashes if the key is pressed to quickly but I will come back to that later I'm ready to move on (I had been stuck on this a while. lol)

[ IF pressed = 0
`restarts the sword animation to 1 after space is pressed
IF SPRITE FRAME(16) < 1: SET SPRITE FRAME 16, 1: ENDIF
play sprite 16, 1, 1, 50
endif
elapsed2=(Timer()-t2)
if keyreleased(57)
pressed = 1
elapsed2 = 0
t2=timer()
endif
`move is taken from other parts of my code that says which
`direction the character was facing last
if pressed = 1 and (move = 3 or move = 5) and attack = 0

show sprite 16
'char animation
play sprite 14, 4, 4, 10
`sword swing right animation

play sprite 16, 1, 5, 10

move = 5
endif

if elapsed2 >= 70 AND keystate(56)=0
pressed = 0
elapsed2 = 0
t2=timer()
endif

if move = 5 and spacekey()= 0 then move = 3 ]

Login to post a reply

Server time is: 2024-03-29 01:14:13
Your offset time is: 2024-03-29 01:14:13