2 回答

TA貢獻(xiàn)1874條經(jīng)驗(yàn) 獲得超12個(gè)贊
您button = 0
在開始時(shí)定義,但永遠(yuǎn)不要在主循環(huán)中更改其值。在你的drawIntro
函數(shù)中,你檢查if button > 0
或if button == 1
很明顯你永遠(yuǎn)不會(huì)執(zhí)行任何這些if
語句。
您需要通過調(diào)用來捕捉鼠標(biāo)按鈕pygame.mouse.get_pressed()
并弄清楚如何正確切換到下一頁。
順便說一句,您也有if button == 1
3 次,我猜這不是您想要的,因?yàn)?code>if語句會(huì)在編寫時(shí)立即執(zhí)行,因此您的第 3 頁將立即顯示。您需要一些計(jì)數(shù)器來跟蹤下次按下鼠標(biāo)按鈕時(shí)需要顯示的頁面。

TA貢獻(xiàn)1757條經(jīng)驗(yàn) 獲得超7個(gè)贊
button當(dāng)用戶按下鼠標(biāo)按鈕時(shí),您需要增加計(jì)數(shù)器。
該drawIntro函數(shù)不應(yīng)在每個(gè)pygame.MOUSEMOTION事件的事件循環(huán)中調(diào)用一次,而應(yīng)在主while循環(huán)中調(diào)用。此外,更改MOUSEMOTION為每次單擊MOUSEBUTTONDOWN增加button一次。
drawIntro函數(shù)中的條件不正確。
import pygame
pygame.init()
SIZE = (1000, 700)
screen = pygame.display.set_mode(SIZE)
clock = pygame.time.Clock()
button = 0
fontIntro = pygame.font.SysFont("Times New Roman",30)
def drawIntro(screen):
#start
if button == 0: # == 0
screen.fill((0, 0, 0))
text = fontIntro.render("Sigle click to start", 1, (255,255,255))
screen.blit(text, (300, 300, 500, 500))
elif button == 1: #page1
screen.fill((0, 0, 0))
text = fontIntro.render("page 1", True, (255, 255, 255))
screen.blit(text, (300,220,500,200))
elif button == 2: #page2
screen.fill((0, 0, 0))
text = fontIntro.render("page 2", True, (255, 255, 255))
screen.blit(text, (300,220,500,200))
elif button == 3: #page3
screen.fill((0, 0, 0))
text = fontIntro.render("page3", True, (255, 255, 255))
screen.blit(text, (200,190,500,200))
running = True
while running:
for evnt in pygame.event.get():
if evnt.type == pygame.QUIT:
running = False
if evnt.type == pygame.MOUSEBUTTONDOWN: # Once per click.
button += 1
drawIntro(screen)
pygame.display.flip()
pygame.quit()
添加回答
舉報(bào)