我正在嘗試制作音樂播放系統。我創建了一個名為 Circle 的類,它定義了按鈕及其屬性,該類有一個名為 click() 的方法,用于檢測屏幕中的特定區域是否被點擊。 def click(self): """ In general, point x and y must satisfy (x - center_x)^2 + (y - center_y)^2 <= radius^2 """ current_mouse_position = pygame.mouse.get_pos() value_of_equation_at_current_mouse_position = (current_mouse_position[0]-self.x)**2+(current_mouse_position[1]-self.y)**2 if (value_of_equation_at_current_mouse_position <= self.radius**2): if pygame.mouse.get_pressed()[0]: return True else: return False我想在單擊時切換播放和暫停按鈕。我的邏輯: if btn_play.click(): if togglePlayaPause == 1: if paused: pygame.mixer.music.unpause() else: pygame.mixer.music.play() played = 1 togglePlayaPause = togglePlayaPause ^ 1 pygame.time.wait(250) print("clicked") a = 0 b = 1024 paused = Falseif togglePlayaPause == 0: pygame.time.wait(550) if btn_pause.click(): pygame.mixer.music.pause() print("paused") paused = True newSong = 0 played = 0 togglePlayaPause = togglePlayaPause ^ 1 pygame.time.wait(250)if togglePlayaPause == 1: btn_play.draw()else: btn_pause.draw()由于播放和暫停按鈕位于相同的坐標上,因此 clik() 方法對兩者都返回 true,并且兩個 if 語句都執行,結果音樂在播放一段時間后暫停。我該如何解決這個問題?
添加回答
舉報
0/150
提交
取消