The menu I have written for my game seems to be very slow / laggy when I click on an option (or press a key).
Moving up and down via the mouse or cursor keys is fine, it's just sometimes slow when I click on an option. For example if I click on "Quit" it may take a couple of seconds to recognise this, by which point I've moved up to "load game" and rather than quitting it tries to load a game. Then the next time I do the same thing it could be fine.
I think it must either be my event handler, or the that I have multiple "if" statements within my "case"
The menu I'm using needs to work for both mouse and keyboard controls.
I'd be grateful if someone could have a look at my code, or provide some code for a working mouse and keyboard menu system
thanks in advance :-)
Moving up and down via the mouse or cursor keys is fine, it's just sometimes slow when I click on an option. For example if I click on "Quit" it may take a couple of seconds to recognise this, by which point I've moved up to "load game" and rather than quitting it tries to load a game. Then the next time I do the same thing it could be fine.
I think it must either be my event handler, or the that I have multiple "if" statements within my "case"
The menu I'm using needs to work for both mouse and keyboard controls.
I'd be grateful if someone could have a look at my code, or provide some code for a working mouse and keyboard menu system
thanks in advance :-)
Function mainMenu:Int() Local tmr:Int = MilliSecs() Local startGame:Int = 0 Local quitGame:Int = 0 Local refreshTimer:TTimer = CreateTimer(60) 'kicks in the EventID so we can use the key handler in a Case menuSelection.cursorY = (yMiddle - 175) menuSelection.cursorX = (xMiddle - 100) Local tmr2:Int = MilliSecs() 'set up the diffculty default level from the gameInfo file If gameInfo.level = 1 Then menuselection.diffLevelFrame = 0 ElseIf gameInfo.level = 2 Then menuSelection.diffLevelFrame = 1 Else If gameInfo.level = 3 Then menuSelection.diffLevelFrame = 2 EndIf While startGame = 0 And quitGame = 0 And (Not AppTerminate()) Cls menuSelection.drawBackground(xMiddle, yMiddle, gameInfo.xRes) menuSelection.drawTitle(xMiddle, yMiddle) menuSelection.drawMenu(xMiddle, yMiddle) 'Mouse Controls 'If the mouse has moved then show it on screen If MouseX() <> mouseSelect.initialX Or MouseY() <> mouseSelect.initialY Then ShowMouse() 'work out the y value of the mouse and set the value used below to highlight 'the cursor position If MouseY() > (yMiddle - 175)+50 And MouseY() <= (yMiddle - 125)+50 Then menuSelection.cursorY = (yMiddle - 125) Else If MouseY() > (yMiddle - 125)+50 And MouseY() <= (yMiddle - 75)+50 Then menuSelection.cursorY = (yMiddle - 75) Else If MouseY() > (yMiddle - 75)+50 And MouseY() <= (yMiddle - 25)+50 Then menuSelection.cursorY = (yMiddle - 25) Else If MouseY() > (yMiddle - 25)+50 And MouseY() <= (yMiddle + 25)+50 Then menuSelection.cursorY = (yMiddle + 25) Else If MouseY() > (yMiddle + 25)+50 And MouseY() <= (yMiddle + 75)+50 Then menuSelection.cursorY = (yMiddle + 75) Else If MouseY() > (yMiddle + 75)+50 And MouseY() <= (yMiddle + 125)+50 Then menuSelection.cursorY = (yMiddle + 125) Else If MouseY() > (yMiddle + 125)+50 And MouseY() <= (yMiddle + 175)+50 Then menuSelection.cursorY = (yMiddle + 175) Else If MouseY() > (yMiddle + 175)+50 And MouseY() <= (yMiddle + 225)+50 Then menuSelection.cursorY = (yMiddle + 225) EndIf EndIf 'highlight cursor position Select menuSelection.cursorY Case (yMiddle - 125) highLightText(1,0,0,0,0,0,0,0) Case (yMiddle - 75) highLightText(0,1,0,0,0,0,0,0) Case (yMiddle - 25) highLightText(0,0,1,0,0,0,0,0) Case (yMiddle + 25) highLightText(0,0,0,1,0,0,0,0) Case (yMiddle + 75) highLightText(0,0,0,0,1,0,0,0) Case (yMiddle + 125) highLightText(0,0,0,0,0,1,0,0) Case (yMiddle + 175) highLightText(0,0,0,0,0,0,1,0) Case (yMiddle + 225) highLightText(0,0,0,0,0,0,0,1) End Select Flip WaitEvent() Select EventID() Case EVENT_TIMERTICK Select True Case KeyDown(KEY_DOWN) menuSelection.down(yMiddle) Case KeyDown(KEY_UP) menuSelection.up(yMiddle) Case KeyDown(KEY_RETURN), KeyDown(KEY_SPACE), KeyDown(KEY_RIGHT), MouseHit(1), JoyDown(0,0) If menuselection.cursorY = (yMiddle - 125) Then 'startGame startGame = 1 pickScenario() Return 0 Else If menuselection.cursorY = (yMiddle - 75) Then 'load game Local ret:Int = loadGame("gameInfo.sav", "galanors.sav", "shadowLords.sav", "Fortress.sav", "runeRing.sav", 1) startGame = 1 Return 1 Else If menuselection.cursorY = (yMiddle - 25) Then 'change difficulty If gameInfo.level = 1 Then gameInfo.level = 2 menuSelection.diffLevelFrame = 1 Else If gameInfo.level = 2 Then gameInfo.level = 3 menuSelection.diffLevelFrame = 2 Else If gameInfo.level = 3 Then gameInfo.level = 1 menuselection.diffLevelFrame = 0 EndIf Else If menuselection.cursorY = (yMiddle + 25) Then 'graphic options graphicOptions() Else If menuselection.cursorY = (yMiddle + 75) Then 'define keys FlushKeys defineKeys() Else If menuselection.cursorY = (yMiddle + 125) Then 'introduction gameInfo.glMovementSound.Play displayInstructions("readme.txt") Else If menuselection.cursorY = (yMiddle + 175) Then 'instructions displayBackStory("backgroundStory.txt", "races.txt") Else If menuselection.cursorY = (yMiddle + 225) Then 'quit quitGame = 1 Return 2 EndIf Delay 100 'so joystick doesn't go repeatedly End Select End Select FlushKeys FlushJoy(0) 'update the mouse values on the main menu If MilliSecs() > tmr + 500 Then tmr = MilliSecs() mouseSelect.initialX = MouseX() mouseSelect.initialY = MouseY() EndIf Wend 'if we get here the user has clicked on the "x" to close the window quitGame = 1 Return 2 End Function