Blocking Background Interactions while Inventory is Open

  • #1, by nate-ingraciaMonday, 30. September, 02:42 6 days ago
    So I'm having a problem with my game's Inventory system. When you open the Inventory, it brings up a box in the middle of the screen, with a bit of margin on the outside. The interface area is limited to the interior of the box, so that I can have an interaction that closes the Inventory when the cursor leaves the area. If you open the Inventory while your cursor is outside the box, the Inventory persists until you move the cursor inside, at which point it can be removed from the box, closing the Inventory.

    The problem I am experiencing is that when you open the Inventory while the cursor is outside the box, you can still click items in the main room and the character can still walk around, but there's a giant box in the way. I'm looking for a way to disallow all background interactions while the Inventory is open.

    Newbie

    15 Posts


  • #2, by jessica-collinsMonday, 30. September, 08:22 6 days ago
    papa's games louie: create a semi-transparent overlay covering the entire screen when the Inventory opens. This overlay should capture all mouse events, preventing clicks from reaching the underlying game elements. Ensure that when the Inventory is opened, you disable input handling for the main game. This can be done by setting a flag (e.g., isInventoryOpen) and checking it in your input handling functions. If the flag is true, ignore all input events related to movement and interactions. If applicable, you can lock the cursor to the Inventory box when it opens. This way, the player cannot interact with the background until they close the Inventory. Implement an input blocker that listens for any mouse or keyboard events when the Inventory is open. If such an event occurs, simply ignore it.

    Newbie

    1 Posts

  • #3, by esmeraldaMonday, 30. September, 09:16 6 days ago
    while this was obviously a spam-bot answering you, one thing was a viable solution:

    create a second interface with a transparent background as big as your game resolution.

    show this second interface at the same time you show your inventory. This will block the interaction but you will still be able to trigger the "cursor leaves interface area" action of the inventory.

    When closing the inventory, hide the second interface as well.

    Make sure the second interface is in the list of interfaces BELOW the inventory.
    This list defines the order of the interfaces in the game when they are shown at the same time. When the interface used to block the input is in the list below the inventory, it will be below the inventory in the game, so you can access the inventory.


    The forum is a bit deserted by now (bots galore, but not many users). It's much more lively in the Visionaire Discord server. So if you want quicker help and more people answering, consider dropping by there. The link is at the bottom of the page.

    Key Killer

    529 Posts

  • #4, by nate-ingraciaMonday, 30. September, 16:22 6 days ago
    Ah, thanks for the help! It actually was not obvious to me that was a bot, I didn't expect bots to have somewhat coherent answers lol

    Definitely joining that discord

    Newbie

    15 Posts

Write post