How do I test for length of keydown?

Get help using Construct 2

Post » Thu Apr 21, 2016 12:04 am

Or in other words, how do you Construct2 experts switch from idle animation to walk animation to a run animation?

I am using Spriter for all of my imported animation and I'm not using default controls, (arrows left/right). What I would think I would be looking for is: KEYBOARD LEFT ARROW IS DOWN FOR xx, THEN PLAYER SET ANIMATION TO RUN.

Cheers community!
B
30
S
13
G
5
Posts: 9
Reputation: 4,658

Post » Thu Apr 21, 2016 12:06 am

Sorry, I tried a few differnt search terms and found this:

"Use the System.time expression when the key is pressed - store it in a variable. When the key is released you can use the System.time expression again to get the new time, subtract the old time (which you stored in a variable) to get the length of time the key was held."

Sorry again, didn't mean to waste anyone's time.

Cheers!
B
30
S
13
G
5
Posts: 9
Reputation: 4,658

Post » Thu Apr 21, 2016 12:59 am

@codexstudios

Thanks for being one of the few who doesn't say "nvm fixed it" without telling an answer for future people. Helped me out!
B
8
S
2
Posts: 15
Reputation: 530

Post » Thu Apr 21, 2016 1:52 am

@elek

Keep in mind that the above is actually tracking when a key is RELEASED and using the system time to subtract from. So it's not quite the solution I had originally posted that I was looking for. But I just got back from dinner and will be working on it and when I have an update I will post it here!

Cheers!
B
30
S
13
G
5
Posts: 9
Reputation: 4,658

Post » Thu Apr 21, 2016 8:27 am

Suppose you use Platform.

Then you have the expression Sprite.Platform.VectorX to compare for.

When Sprite.Platform.VectorX = zero >> play idle
When Sprite.Platform.VectorX < X or = x and not zero >> play walk (put x to your liking)
When Sprite.Platform.VectorX > x >> play run

Set the Acceleration of the platform to have enough 'walking time'.

The platform does nothing when no key pressed, so those purely run on what the character is actual dooing.
But, keep in mind that you probaly have to jump too, you dont want them running mid air.

So they can also be true when the character is jumping. In that case they need a second condition.
Like:
(condition1) When > x and (condition 2) platform is on the floor > play run

You might have to add a 'do once while true' to all that.
B
33
S
18
G
27
Posts: 2,440
Reputation: 20,344


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 3 guests