Change animation frame by pressing a button

Get help using Construct 2

Post » Wed Nov 06, 2013 12:49 am

Yeah, i use same way. I kind of understand why it works, but don't know how to explain it XD Not sure if it's the right way too and will not introduce some lags in the long run.
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
91
S
30
G
22
Posts: 1,985
Reputation: 20,149

Post » Wed Nov 06, 2013 5:14 am

So, your events were like this?
[code]keyboard: on down arrow pressed
mainmenu_items: animation frame=0
---> mainmenu_items: set animation frame=1

keyboard: on down arrow pressed
mainmenu_items: animation frame=1
---> mainmenu_items: set animation frame=2

keyboard: on down arrow pressed
mainmenu_items: animation frame=2
---> mainmenu_items: set animation frame=0[/code]
Adding the wait works well as you delay the frame from getting set right away so the 2nd and 3rd events won't be true and run. On a side note you should be able to do "wait 0" as it will just delay till the end of the event sheet.

Another approach I like to take in a situation like this is to also use the modulus operator to simplify the logic. eg:
[code]keyboard: on down arrow pressed
---> mainmenu_items: set animation frame= (mainmenu_items.AnimationFrame+1)%3

keyboard: on up arrow pressed
---> mainmenu_items: set animation frame= (3+mainmenu_items.AnimationFrame-1)%3[/code]
B
94
S
33
G
113
Posts: 5,356
Reputation: 73,273

Previous

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 7 guests