Menu highlighting with Xbox controller/Arrow keys

For questions about using Classic.

Post » Sun Jun 13, 2010 10:44 pm

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.

~t
B
4
S
1
G
2
Posts: 61
Reputation: 997

Post » Sun Jun 13, 2010 11:53 pm

[url:1nw6440x]http://dl.dropbox.com/u/1013446/choices.cap[/url:1nw6440x]
ask questions if you have em

control with left/right arrow keys
Spriter Dev
B
87
S
21
G
12
Posts: 3,240
Reputation: 16,461

Post » Mon Jun 14, 2010 2:43 am

Excellent! Appreciated Lucid, this will get me going.

~t
B
4
S
1
G
2
Posts: 61
Reputation: 997

Post » Wed Jun 16, 2010 1:54 am

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?

[url:1ex454df]http://www.box.net/shared/8svet79mpx[/url:1ex454df]

[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.

[code:1ex454df]Blue: Unique ID is 1/2/3[/code:1ex454df]

[/Edit]

thx man!
B
4
S
1
G
2
Posts: 61
Reputation: 997

Post » Wed Jun 16, 2010 3:26 am

something along the lines of
on keyboard press enter
-----goto layout global('screenselect')

or

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


as for clamp

clamp(x,a,b)
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
Spriter Dev
B
87
S
21
G
12
Posts: 3,240
Reputation: 16,461

Post » Wed Jun 16, 2010 3:41 am

Awesome, thx for the explanation on the clamps, makes perfect sense. As for the events is
[code:9jlg6lmm]on keyboard press enter
-----goto layout global('screenselect')[/code:9jlg6lmm]

used in conjunction with the "Blue Unique ID" I posted?

[color=#BF0000:9jlg6lmm][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][/color:9jlg6lmm]
B
4
S
1
G
2
Posts: 61
Reputation: 997

Post » Wed Jun 16, 2010 3:57 am

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
Spriter Dev
B
87
S
21
G
12
Posts: 3,240
Reputation: 16,461

Post » Wed Jun 16, 2010 4:44 pm

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!

~t
B
4
S
1
G
2
Posts: 61
Reputation: 997

Post » Wed Jun 16, 2010 7:48 pm

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
Spriter Dev
B
87
S
21
G
12
Posts: 3,240
Reputation: 16,461

Post » Thu Jun 17, 2010 2:15 am

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:

[code:2pk30t3i]+ 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 "Layout " & Blue.Value('ID') instead of Blue.Value('choiceName'), 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:

[url:2pk30t3i]http://dl.dropbox.com/u/5868916/prototype_brawler3%282%29.cap[/url:2pk30t3i]

Good luck. :)
B
3
S
2
G
2
Posts: 187
Reputation: 1,449

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 8 guests