// Check Pointer thisMenuSelected = 0 for i=1 to MENU_ITEMS if getTextHitTest( menuText[ i ] , PointDX() , PointDY() ) > 0 thisMenuSelected = i exit endif next iThis uses the getTextHitTest() command, which returns a 1 if the pointer is currently within the bounds of the text object used by that menu option. If so, then the loop value (and so the menu option) is stored in thisMenuSelected. This is the current menu option.
Then it enters the three part structure outlined previously. First checking if the pointer was just pressed.
if getPointerPressed() > 0 // Pointer Pressed touch.menuPicked = thisMenuSelected if thisMenuSelected > 0 then setTextColorGreen( menuText[ thisMenuSelected ] , 255 )This copies the current menu option just obtained to the global field touch.menuPicked. This is the picked menu option.
If this value is not zero, then the corresponding text item is highlighted by setting it's green value to 255.
If the pointer was just released, the second block is used.
elseif getPointerReleased() > 0 // Pointer Released if thisMenuSelected > 0 and thisMenuSelected = MenuPicked() then StartTransition( TRANS_FADEOUT , MENU_FADE )This checks that the current menu option is not zero and matches the picked menu option using MenuPicked().
If both cases are true, it begins the fade out transition.
If the pointer is still held, the third block is used.
elseif getPointerState() > 0 // PointerHeld if MenuPicked() > 0 if thisMenuSelected = MenuPicked() setTextColorGreen( menuText[ MenuPicked() ] , 255 ) else setTextColorGreen( menuText[ MenuPicked() ] , MENU_GREEN ) endif endif endifIf the picked menu option is not zero, then it checks if the current menu option is the same the one picked, setting the green to 255 if this is the case, otherwise setting it back to its original colour.
If the user moves off the picked option, it is un-highlighted.
If the user then moves back onto it without releasing the pointer, it is re highlighted.
If the user releases the pointer on the picked option, the menu fades out.
This is the complete pointer check routine.
// Check Pointer thisMenuSelected = 0 for i=1 to MENU_ITEMS if getTextHitTest( menuText[ i ] , PointDX() , PointDY() ) > 0 thisMenuSelected = i exit endif next i if getPointerPressed() > 0 // Pointer Pressed touch.menuPicked = thisMenuSelected if thisMenuSelected > 0 then setTextColorGreen( menuText[ thisMenuSelected ] , 255 ) elseif getPointerReleased() > 0 // Pointer Released if thisMenuSelected > 0 and thisMenuSelected = MenuPicked() then StartTransition( TRANS_FADEOUT , MENU_FADE ) elseif getPointerState() > 0 // PointerHeld if MenuPicked() > 0 if thisMenuSelected = MenuPicked() setTextColorGreen( menuText[ MenuPicked() ] , 255 ) else setTextColorGreen( menuText[ MenuPicked() ] , MENU_GREEN ) endif endif endifTo act on the menu option, the program must look for the fade out to complete, so it's back to the previous section.
Now the line.
if TransitionCount() = 1.0 then StopTransition()Is replaced with.
if TransitionCount() = 1.0 if Transition() = TRANS_FADEOUT select MenuPicked() case 1 // Menu Option 1 setGameState( STATE_RUNNING ) endcase case 2 // Menu Option 2 setGameState( STATE_EXIT ) endcase case 3 // Menu Option 3 endcase case 4 // Menu Option 4 endcase case 5 // Menu Option 5 endcase endselect endif StopTransition() endifWhich checks if the transition is a "fade out", in which case it starts another select structure, this time for the menu option picked.
In each case, the game state is changed to match the option picked.
As with the initial menu strings, additional case statements are included to allow other menu options to be added.
We now have a fully working menu, which fades in, processes user selections, fades out and acts upon those selections.
No comments:
Post a Comment