Python Forum
[PyGame] Mouse.get_pressed() Overlapping Buttons
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] Mouse.get_pressed() Overlapping Buttons
#3
(Dec-28-2016, 09:12 AM)Mekire Wrote:
(Dec-28-2016, 09:04 AM)KHendrikson Wrote: As a note, the different menu screens are in the same general function, split between parts of it, to make navigating easier.
Hard to say without seeing code, but this worries me.

I think you should look into how to design a multi scene program before continuing.
https://github.com/Mekire/pygame-mutisce...with-movie

The code itself is pretty simple, since I'm new to Pygame. The screens share a similar background and thus the whole screen doesn't need to be updated each time, rather the contents of the menus, so I thought it would be easier to keep it within the same function. Do you think splitting it between functions would solve the issue?

menu = 'menu'
while True:
   mouse = pygame.mouse.get_pos()
   click = pygame.mouse.get_pressed()
   if menu == 'menu':
       # Displays main options menu
       # Looks for key presses to navigate through options (works great)
       # Looks for mouse position and presses:
       if x < mouse[0] < x+i and y < mouse[1] < y+j:
           if click[0] == 1:
               menu = 'attack'
       elif ...:
           if click[0] == 1:
               menu = 'item'
       elif ...:
           ...
   if menu == 'attack':
       # Displays the different attacks menu
       # Since the attack screen shares some button coordinates,
       # after switching menu = 'attack' it starts scanning for new input
       # relating to the new coordinates. And since the coordinates are
       # the same, and it still detects the button being pressed, it activates
       # the next button.

       # If you want to go back to the previous menu you'd just switch menu = 'menu' again
   if menu == 'item':
       # Displays the Item menu
       # ...
   pygame.display.update()
   clock.tick(30)


I've now also tried to split the menu between different functions, setting new variables for get_pos() and get_pressed() in them, but that has also failed to work.
Reply


Messages In This Thread
RE: Mouse.get_pressed() Overlapping Buttons - by KHendrikson - Dec-28-2016, 09:25 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020