How do I test for length of keydown?

  • 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!

  • 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!

  • 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!

  • 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!

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)