How do I check against all keycodes inside a family?

0 favourites
  • 2 posts
From the Asset Store
A collection of various zombie characters sprites for creating a 2D platformer or sidescroller game
  • I have a family of 8 players, each using one key for the game. There's a family variable keycode, and I save the keycode on it.

    However, I want to issue actions for the keycode is_down/release, and I'm wondering if I can do it with the family (instead of making 8 repeated actions for all the players).

    I did this to allow for the down to be detected, and it appears to work fine:

    keyboard: on any key pressed

    keyboard: keycode keyboard.lastkeycode is down

    system: pick players by evaluating players.keycode = keyboard.lastkeycode

    Then performing the required actions (I would get to them with "keyboard: keycode player1.keycode is down" if I wasn't doing this, but would have to repeat for all the players.

    Is there a way to detect the release of the key with the family?

    Also, am I doing it right for the down event or is there a better way?

    Thank you very much in advance!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • For bound keys with 'Key released' functionality, I used two dictionaries. The dictionaries stored which key was down each tick by recording its keycode (you can also store the player ID in the value to simplify other code I would have thought). At the end of each tick the game loop would evaluate which dictionary keys were present this tick, and compare it to the keys present in the previous tick.

    If the key is now present, but was previously absent, call a function that corresponds to 'Key pressed'

    If the key is present in both, call a function that corresponds to 'Key down'

    If the key was present in the previous tick, and absent in the current tick, call ... 'Key released'!

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