• Hi

    Below you can find some example code to illustrate my problem.

    When I select "Start a game" in the menu, I start my game. But when I press BTN1 "in the game", the menu keeps flashing and when I press BTN1 / BTN2, the menu items are selected again and the game function for these buttons are activated too.

    So how can I stop the built in button watches of the E.showMenu() function? Or what am I doing wrong?

    Greets

    Stijn

    // Game functions
    function startGame () {
      g.clear();
      g.setColor("#ffffff");
      g.drawString("game started", 50, 100);
      
      setWatch(function() { 
        g.clear();
        g.setColor("#ffffff");
        g.drawString("btn 1 pressed", 50, 110); 
        console.log("btn 1 pressed");
      }, BTN1, {repeat: true});
      
      setWatch(function() { 
        g.clear();
        g.setColor("#ffffff");
        g.drawString("btn 2 pressed", 50, 120); 
        console.log("btn 2 pressed");
      }, BTN2, {repeat: true});
    }
    
    // Global functions
    function closeApp() {
      console.log("App closed");
      load();
    }
    
    // --- Menu
    var mainMenu = {
      "": { "title": "Menu" },
      "Start a game": () => startGame(),
      "Exit" : () => closeApp(),
    };
    
    function onInit(){
      E.showMenu(mainMenu);
    }
    
    // --- Initialize app
    onInit();
    
  • Hi!

    The issue is that the menu likes to stay around until it is explicitly removed - there are a few cases where it's handy.

    However all you need to do is call E.showMenu(); to remove the menu:

    var mainMenu = {
      "": { "title": "Menu" },
      "Start a game": () => {
         E.showMenu();  // <------------------------ this
         startGame()
       },
      "Exit" : () => closeApp(),
    };
    
  • Thanks works perfect!

    Might be a good idea to add to the documentation what E.showMenu() does.

  • Thanks! I've just updated the docs and they'll go live in a bit.

    It was shown in code example (for the Exit menu item), but wasn't very obvious.

  • Thanks, Gordon.

    Thumbs up for your efforts and quick responses. And Bangle.js is real fun ;-)

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

E.showMenu: watches on BTN's stay active when menu is left

Posted by Avatar for skelesp @skelesp

Actions