How do I create an event for when 2 keys are down?

0 favourites
From the Asset Store
Random Maze Generator with Door & Key System - tutorial capx
  • Hello, friends!

    I recently started using Construct and I want to use a sprite sheet I've been working on for some time. Basically, the gameplay of my project is seen from an isometric point of view and I already programmed the sprite to move up, down, left and right without any problems at all. The real issue pops up once I press the left or right arrow, along with the up or down arrow. What I would like to do is use the same animations I already made for walking up, down, left and right, but for diagonal movement.

    Say, I want the character to move towards the bottom right corner of the map. In that case, I have 2 options. I can either press the [↓] key and then the [→] key, or, I could press the [→] key first and then the [↓] key. In the first case, I would set the "Walk Down" animation, and in the second case, the "Walk Right" animation. In a way, what I want to accomplish is a movement system similar to the one in Don't Starve and Zelda: Minish Cap, where the characters only have 4 different walking animations but 8 different directions they can move towards.

    Unfortunately, I don't know how to make an "if X key is down and then Y key is pressed" event, so I would appreciate any advise on this matter.

    Reason for edit: I originally wrote "top-down", instead of "isometric". Apologies!

  • I haven't look the Zelda game, but I think that you want something similar to this, and, if not, you can figure out the logic and work it out.

  • Sadly, that doesn't really help me. My animations can't be flipped nor mirrored since you don't see the player model from a top-down perspective, but rather from an isometric point of view. That being said, the "walk down" and "walk up" animations are completely different. I apologise for the confusion, since I just realised I wrote "top-down" in the OP. I'll correct it immediately.

  • I used the same 2 frames just for convenience. You will not use frames but animations after all. My point was to eliminate the animation change when moving diagonally.

    I am re-attaching the file with some changes, the logic is exactly the same.

  • Marvelous! It worked! Thank you so much!

  • Sorry, I have a new, albeit small issue. The walking animation gets stuck in the first frame whenever I move in a diagonal line. Do you know what could be causing this?

  • Can you share your capx? Or a simplified version of it..?

  • Unfortunately, I can't share the capx file at the moment, but here's pretty much all there is to the project in question. All I've done so far is work on the sprites in Photoshop, so I don't have that much to share Construct2-wise.

  • Try not to use the "On X button released". Instead use the "8direction is moving" and the inversion of it to change from "Walk" to "Look" animations. Use an instance variable to set the direction that the player is facing.

    See the updated capx.

  • Excuse me, but how did you manage to "set direction"? I can't find that anywhere. I apologise if that's a dumb question but again, I'm new to Construct 2 as an engine.

  • No problem, I am glad to help.

    So, in my example, events 6,7,8 and 9 are checking the key-presses and store a "direction" into an Instance Variable. This variable exists on the Player Sprite object. Click on the Player and you will see on his properties that under the "Instance Variables" category, a Variable named "Direction" exists and it's initial value is "Right". You can add/remove/edit Instance Variables by clicking on the "Instance variables" link.

    So, after the direction is stored in the variable, events 10 and 15 check if the player is moving or not and then, within the sub events, decide which animation should be played.

    You don't have to use an Instance variable, you could use a global variable and the result would be just the same, but in practice you want less global variables, for organization purposes.

    I hope that makes sense

  • Alright, I'll give it a go and I'll get back to you!

  • I like the idea of using an instance variable, since they usually keep everything nice and tidy, but every time I try to make an action to change its value, it says that "down" is an unknown expression and "right" "does not take 0 parameters". I think I might be wrong, but I'm supposed to use "Instance Variables -> Set Value", right? Is that the action I'm supposed to use? I still don't know how to set the direction to anything, as I just don't know which action I should use.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I like the idea of using an instance variable, since they usually keep everything nice and tidy, but every time I try to make an action to change its value, it says that "down" is an unknown expression and "right" "does not take 0 parameters". I think I might be wrong, but I'm supposed to use "Instance Variables -> Set Value", right? Is that the action I'm supposed to use? I still don't know how to set the direction to anything, as I just don't know which action I should use.

    To use an instance variable inside an expression, you have to write it in the format : Object.Instance_Variable (e.g. Sprite.Down, Enemy.HP, etc..)

    To set it, you just have to select it from the dropdown list, and to enter the value you want

  • > I like the idea of using an instance variable, since they usually keep everything nice and tidy, but every time I try to make an action to change its value, it says that "down" is an unknown expression and "right" "does not take 0 parameters". I think I might be wrong, but I'm supposed to use "Instance Variables -> Set Value", right? Is that the action I'm supposed to use? I still don't know how to set the direction to anything, as I just don't know which action I should use.

    >

    To use an instance variable inside an expression, you have to write it in the format : Object.Instance_Variable (e.g. Sprite.Down, Enemy.HP, etc..)

    To set it, you just have to select it from the dropdown list, and to enter the value you want

    Where should I write this instance variable?

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