Menu highlighting with Xbox controller/Arrow keys

This forum is currently in read-only mode.
From the Asset Store
Full game Construct 2 and Construct 3 to post on Google Play
  • Hiya me again, I'm going to begin an official "my new game" thread once I get all the moving parts stable, so I'm not flooding the forums

    Ok so I would like to create a simple game menu that I can use either the Xbox Dpad/Keyboard arrows to cycle through the choices (start game/options/credits e.t.c) and by doing so they highlight in turn, and once highlighted I can activate them by a button/key press.

    Couldn't find anything in the forum search, so hopefully someone has an idea on how to approach this or maybe point me to an aptly named thread that I missed.



    ask questions if you have em

    control with left/right arrow keys

  • Excellent! Appreciated Lucid, this will get me going.


  • Hiya Lucid, got this working with individual objects... yay! (cap link below) now I'm not too sure how you would check to see which object is selected within the loopindex so when you push a key or a button it would go to that particular layout. Also can you briefly explain what the "clamp" actions are doing?

    [Edit] Ok I got further using the below, but now it's just figuring out how to use the same button/key press for each selection.

    Blue: Unique ID is 1/2/3[/code:1ex454df]
    thx man!
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • something along the lines of

    on keyboard press enter

    -----goto layout global('screenselect')


    ----goto layout global('choicename')

    as for clamp


    it just gives you back x, but forces the value to stay between a and b

    so clamp(5,10,20) = 10

    clamp(15,10,20) = 15

    and clamp(25,10,20) = 20

    the clamps in the cap are just clamping global('screenselect')+1 (or minus 1) to be between either 1 or the total number of 'choice' objects. screenselect is your current selection, and you're just adding one to go to the next object or subtracting to go to the previous, but you don't want it your selection to be able to go less than 1, or higher than the total number of choices, or nothing would be highlighted when you checked screenselect against each objects ID private variable

    in the start of layout you loop through all objects from left to right by ordering them by their x locations to set their ID. this makes it so you don't have to worry about which object has which ID if you decide to rearrange them later, it will always be ordered from left to right

  • Awesome, thx for the explanation on the clamps, makes perfect sense. As for the events is

    on keyboard press enter
    -----goto layout global('screenselect')[/code:9jlg6lmm]
    used in conjunction with the "Blue Unique ID" I posted?
    [Edit] Ok I managed to get the options/credits working but start game doesn't and when I return back to the main screen, everything stops working... so I'm guessing an "Always on every tick" event is needed" [/edit]
  • the only problem with the unique ID is that it can change when you're changing you're layout

    add some text, maybe copy paste one of your choices, and it takes a little effort to figure out which UID is which, I think it would be easier to just get the global that keeps track of choice, because you'll know the exact order, or better yet the string for the choice name of the sprite, that way it's easy, readable, and you don't have to think about UID's. This is my own general rule of thumb, but I think UIDs should only be used as a last resort. they just make for messy event logic imho

    the easiest would be to have the sprites PV be the name of the layout

    sprites private variable 'ID' = screenselect

    -----go to layout( sprite pv choicename)

    simple, elegant, readable, easy to maintain in the face of changes down the line

  • Sorry Lucid, you kinda lost me there... can you provide an example in the .cap above or a new one if you wish. Then I'll re-read your last post... it's kinda hard for me to visualize what you mean.

    Are you saying instead of using numbers I should use text as the value for ID? And leave the 'choiceName' var as is?

    thx much!


  • You don't have to change anything. I just meant, name you button "choicename" variable after the layout it will take you to,

    Instead of 'set text' to choicename

    On button press

    --goto layout "choicename"

    I also meant the same could be done with the id variable and layout numbers

  • Hi, I was interested in this problem, so I took a look at it.

    That's a nice way to set up a variable number of choices in a selection menu, lucid.

    Anyway, I made a couple of changes to make it work, lildragn. The main change is just what happens when you hit enter:

    + MouseKeyboard: On key Enter pressed
    + Blue: Pick by Blue.Value('ID') Equal to global('screenSelect')
    -> System: Go to layout Blue.Value('choiceName') with transition "None" lasting 0 MS[/code:2pk30t3i]
    This is one way to do it. Note that here it's telling Construct to go to the layout with the same name as the contents of the string in the variable 'choiceName'. As lucid mentioned, if your target layouts were named as "Layout 1", etc., you could very well use [i]"Layout " & Blue.Value('ID')[/i] instead of [i]Blue.Value('choiceName')[/i], or some other scheme entirely. The picking of the menu item was the main thing to accomplish there, so you can get the ID or choiceName for it.
    The other changes that I made were just things that I would have done differently, to the same result, though. Here is the modified .cap:
    Good luck.
  • Haha ok, I don't think I would've gotten that. Thanx for the well commented .cap file, I remember doing something similar with 'loopindex' when I was playing around xCode for iPhone. This actually makes alot of sense to me. It's frustrating at time, I can read code but putting it into a tangible string that makes sense is where it becomes tricky

    Really appreciate it Silent!


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