args['d'].set_is_visible(True) button.set_on_click(show_dialog, {'d': dialog}) backgroundview = View(0, 0, 1000, 1000) backgroundview.fill(pygame.Color(255, 255, 255)) backgroundview.set_alpha(255) # ENTER MAIN GAME LOOP while not crashed: for event in pygame.event.get(): if event.type == pygame.QUIT: crashed = True backgroundview.draw(pygame.mouse, gameDisplay) # When a view isn't available, it's best to never draw it at all button.draw(pygame.mouse, gameDisplay) # Draw the dialog over the button if visible dialog.draw(pygame.mouse, gameDisplay) pygame.display.update() clock.tick(60)
sub_sub_view = View(20, 20, 100, 300) sub_sub_view.fill(pygame.Color(0, 0, 100)) sub_sub_view.set_alpha(255) # Add sub_sub_view as a subview to sub_sub_view sub_view.add_view(sub_sub_view) overlapping_view = View(50, 50, 300, 50) overlapping_view.fill(pygame.Color(100, 100, 0)) overlapping_view.set_alpha(255) # ENTER MAIN GAME LOOP while not crashed: for event in pygame.event.get(): if event.type == pygame.QUIT: crashed = True # To draw, call view.draw() and pass the mouse input and gameDisplay # Drawing a view will draw all subviews top_view.draw(pygame.mouse, gameDisplay) # Drawing is executed in order, last drawn will be on top overlapping_view.draw(pygame.mouse, gameDisplay) pygame.display.update() clock.tick(120)