basic menu
BlitzMax Forums/BlitzMax Programming/basic menu
| ||
This menu code works but how can i make it so that the menu selection changes smoothly so that one downward push on the gamepad stick changes the selection in one increment and like wise for a upward direction 'Basic Menu Graphics 640,480 Global selected:Int = 1 Local font1 = LoadImageFont("arial" , 18 , True) 'Main Loop While Not KeyHit(KEY_ESCAPE) Cls menu() Local JY#=JoyY#() SetImageFont font1 SetColor 255,255,255 DrawText "selected :"+selected,50,40 DrawText "JoyY# :"+JY#,50,60 SetColor 255 , 255 , 0 DrawText "Simple Menu",200,100 SetColor 255,255,255 If selected = 1 Then SetColor 255 , 0 , 0 Else SetColor 255 , 255 , 255 End If DrawText "Select One",200 , 150 If selected = 2 Then SetColor 255,0,0 Else SetColor 255 , 255 , 255 End If DrawText "Select Two",200 , 200 If selected = 3 Then SetColor 255,0,0 Else SetColor 255 , 255 , 255 End If DrawText "Select Three",200 , 250 If selected = 4 Then SetColor 255,0,0 Else SetColor 255 , 255 , 255 End If DrawText "Quit",200 , 300 Flip Wend Print "Hello World" Print "Selected " +selected End Function menu() If JoyY#() = 1 Then selected=selected+1 If selected > 4 Then selected = 4 If JoyY#() = -1 Then selected=selected-1 If selected < 1 Then selected = 1 If JoyDown(1) Return selected End If End Function |
| ||
When you increment or decrement 'selected', set a variable like 'disableJoy' to 1. Add some extra logic so that selected can only increment and decrement if the joystick is pushed and disableJoy is 0. Add a line that sets disableJoy to 0 if the joystick is not pushed up or down. Also, rather than checking if joyY is 0 or 1, you may wish to add some tolerance in case it is not calibrated properly, for example changing the menu selection if joyY>0.9 rather than when it is equal to 1. |
| ||
Thanks works! |