添加鼠标位置获取与悬停高亮显示

This commit is contained in:
chicrobot committed 2026-07-30 01:23:30 +08:00
1 parent 0d5063838d
commit a50b746ee1
1 file changed
+11
+11
View File
@@ -37,6 +37,9 @@ class MainMenuScene(BaseScene):
# 初始化雨滴
self.init_rain(self.rain_max)
# 鼠标位置
self.mouse_pos = (0, 0)
def update(self):
# 按键按下则切换场景
if self.button_status:
@@ -51,6 +54,9 @@ class MainMenuScene(BaseScene):
# 雨滴坠落
self.rain_fall()
# 更新鼠标位置
self.mouse_pos = pygame.mouse.get_pos()
def handle_event(self, event):
"""
接收主循环传来的事件并处理
@@ -117,6 +123,11 @@ class MainMenuScene(BaseScene):
text_rect.y = screen_rect.y + count * 2 * text_rect.height + screen_rect.centerx/2
self.screen.blit(text, text_rect.topleft)
count += 1
# 是否高亮显示
if text_rect.y < self.mouse_pos[1] < text_rect.y + text_rect.height \
and text_rect.x < self.mouse_pos[0] < text_rect.x + text_rect.width:
pygame.draw.rect(self.screen, Color.white, text_rect, 1)
def init_rain(self, max_num):
"""