[Example] Dynamic menu

This forum is currently in read-only mode.
From the Asset Store
Unlock platyers earning coins, and save it with Localstorage
  • This demo shows how a dynamic menu can be created using a hashtable. The hashtable contains menu items (such as Start Game, Load Game, Save Game, Exit Game etc.), which are read and used to build the menu with. The menu automatically expands and adds necessary amount of buttons as well as set them up to work with.

    All this can be done in runtime; just change the hashtable entries. See the demo here:

    Menu Demo cap

    I am open for alternatives and optimization tips.

    Bug: Also, in this demo the debugger bug is apparent. Run in debug mode, open and close menu, in the instances list in debugger the MenuButton shows as 0 instances, but it contains entries. Clicking one of them will cause a crash. MenuButton is a container object, contained with MenuButtonText, and is destroyed when MenuButtonText is destroyed. Debugger doesn't seem to register this and so refers to non-existing isntances.

  • thats pretty awesome. i think i might use this method for my game later on.

  • Thanks for the good bug report, the debugger thing is fixed in the next build

  • This is very cool. I added a pause by setting the time scale to zero while the menu is up. Here is mipey's awesome cap with a pause added.

    PS: Setting timescale to zero is a good way to make a pause right?

  • PS: Setting timescale to zero is a good way to make a pause right?

    Yes, definitely!

  • As long as menu operations don't make use of timedelta!

  • Nice example, and even though the amount of events would make this a pain to implement for a novice, the scripting should be relatively easy to understand.

    Would be nice to see something like this as an object someday.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • As long as menu operations don't make use of timedelta!

    You actually can use timedelta while paused - you can set it and set it back over a section of events, like:

    + Always

    -> Set timescale to 1

    -> Set Opacity to Opacity + 100 * TimeDelta

    -> Set timescale to 0

  • All this can be dumped into its own event sheet and then pushed aside to be included in any layouts where necessary. A simple way to execute actions linked to buttons would be with a function call.

    MouseKeyboard: On Left Either single or double clicked on Blue

    FunctionCall function Blue('MenuItem') (and Forget picked objects)[/code:2f5tekex]

    As you can see, this calls a function with name taken from the menu button variable. The function can be stored anywhere, best on the layout event where menu was generated (assuming the button clicked has "exit" stored within MenuItem variable):

    Function: On function "exit"

    System Close application[/code:2f5tekex]

    That is all it takes. And when you need to disable the menu after clicking a button, just set the global variable 'MenuToggle' to 0 within the called function. Poof, menu gone. Hooray for clean code (at least within the layout sheets)!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)