News:

Building a 3D Ray Tracer  By stevmjon

Main Menu

Menu Cursor Locking

Started by Makeii Runoru, July 07, 2008, 12:00:36 AM

Previous topic - Next topic

Makeii Runoru

I'm designing a sample menu, but whenever I want to do this, I have to set a variable as a locker to lock the cursor's position. Or else, holding down the up or down button will scroll the cursor every frame.

This is my code. I've made it a bit colorful just for kicks.

SetFPS 30

Type tMenu
x
y
width
height
counter
countermax
EndType

Type tCursor
active
max
EndType

fadecounter = 100
fadeindex = 0 //indicating that the fadecounter is decreasing or increasing

Dim Cursor As tCursor
Dim Menu As tMenu


Menu.x = 200
Menu.y = 200
Menu.width = 100
Menu.height = 200

Cursor.active = 1
Cursor.max = 6

button = 0

Do
Cls RGB(0,0,fadecounter)



If fadeindex = 0
Dec fadecounter
EndIf

If fadeindex = 1
Inc fadecounter
EndIf

If fadecounter = 0
fadeindex = 1
EndIf

If fadecounter = 100
fadeindex = 0
EndIf

If DownKey() = 1
If button = 0
Cursor.active = Cursor.active +1
button = 1
EndIf
EndIf

If UpKey() = 1
If button = 0
Cursor.active = Cursor.active -1
button = 1
EndIf
EndIf

Print Cursor.active

Ink RGB(fadecounter,200,200)
Box (Menu.x+2),(Menu.y+2)+((Cursor.active*20)-20),Menu.x+50,(Menu.y+2)+((Cursor.active*20)-20)+10,1

Ink RGB(255,255,255)
Text Menu.x, Menu.y-15, "Beginning Menu"
Text Menu.x+2, Menu.y+2, "Selection"
Text Menu.x+2, Menu.y+22, "Marker"
Text Menu.x+2, Menu.y+42, "Substitute"
Text Menu.x+2, Menu.y+62, "Narda"

Ink RGB(Rnd(255),Rnd(255),Rnd(555))
Box Menu.x, Menu.y, Menu.x+Menu.width, Menu.y+Menu.height, 0
Sync

If SpaceKey() = 1
button = 0
EndIf
Loop


It's a bit cluttered, but I just wanted it to work for now. What can I use so that every time the UpKey or DownKey is pressed, the cursor of the menu will only go up or down once and stay there. (To unlock the cursor, you need to press the Space Key to move the cursor again).
This signature is boring, and could be improved. However, the user of this signature doesn't need a fancy signature because he or she doesn't really care for one.

Makeii Runoru

Haha. Nevermind, I just learned FlushKeys. My bad.
This signature is boring, and could be improved. However, the user of this signature doesn't need a fancy signature because he or she doesn't really care for one.

kevin


You can use the flushkeys solution or monitor the Scancode() state.  When it's ZERO, there's no keys down.  So we reset the 'buttons' flag



SetFPS 30

Type tMenu
x
y
width
height
counter
countermax
EndType

Type tCursor
active
max
EndType

fadecounter = 100
fadeindex = 0 //indicating that the fadecounter is decreasing or increasing

Dim Cursor As tCursor
Dim Menu As tMenu


Menu.x = 200
Menu.y = 200
Menu.width = 100
Menu.height = 200

Cursor.active = 1
Cursor.max = 6

button = 0

Do
Cls RGB(0,0,fadecounter)


If fadeindex = 0
Dec fadecounter
EndIf

If fadeindex = 1
Inc fadecounter
EndIf

If fadecounter = 0
fadeindex = 1
EndIf

If fadecounter = 100
fadeindex = 0
EndIf

If button = 0

if Cursor.active<4
If DownKey() = 1
Cursor.active = Cursor.active +1
button = 1
endif
EndIf

if Cursor.active>1
If UpKey() = 1
Cursor.active = Cursor.active -1
button = 1
endif
EndIf

endif

// Check if there's no input
if Scancode()=0
button=0
endif

Print Cursor.active

Ink RGB(fadecounter,200,200)
Box (Menu.x+2),(Menu.y+2)+((Cursor.active*20)-20),Menu.x+50,(Menu.y+2)+((Cursor.active*20)-20)+10,1

Ink RGB(255,255,255)
Text Menu.x, Menu.y-15, "Beginning Menu"
Text Menu.x+2, Menu.y+2, "Selection"
Text Menu.x+2, Menu.y+22, "Marker"
Text Menu.x+2, Menu.y+42, "Substitute"
Text Menu.x+2, Menu.y+62, "Narda"

Ink RGB(Rnd(255),Rnd(255),Rnd(555))
Box Menu.x, Menu.y, Menu.x+Menu.width, Menu.y+Menu.height, 0


Sync

Loop