I tried to develop a dynamic menu using the same techniques you are, but met with limited success...
An associate suggested the use of an Object Tree.
Now, I didn't know precisely what he meant by that, but it didn't take long to come to grips with the approach.
First, look at the problem in a different way...
Rather than thinking,"Ok, I've got these buttons on the stage and when the user clicks one, I need to move all the lower buttons down, then when the user clicks again I need to remove the extra buttons and move all the other buttons back up into place, etc, etc, etc."
Try this, "Ok I have a list of main menu items to draw on the stage. Where are these items stored? What buttons am I attaching? What are the sub buttons I need to add? etc, etc, etc,"
The main difference is that in the first approach, you are locked into having the 'main' buttons always on the stage and are forced to move them, whereas if your menu is totally dynamic (getting erased and redrawn everytime it is interacted with) and you draw items from a list (when you make the menu), all you need to do is modify the list of items you want to draw, the draw the items on that list.
To do this, you only need to understand two things: The Object Tree structure, and recursive functions.
First you create a tree structure where all your "items" are arranged into a hierarchichal structure: the sub-menu items are child objects of the main-menu items.
If the user clicks one of the 'main-menu" buttons, it "activates" the sub-items (child objects). Then a recursive function is run over the tree structure to 'read' the active items into a list. This is the list of items you will draw to the stage.
If the user then clicks the same button again, the sub-items are 'de-activated', the recursive reader function is called again and the menu is re-drawn.
Using this approach may require a bit more of an initial time investment, but the pay-off is a transferable, scalable, system without the headaches involved with trying to manipulate the positions of all those buttons.
Hope this helps,
PPE
__________________
Ascii Abe says,
"Design to an interface!"
|