第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何在 Pygame 中單擊并轉(zhuǎn)到另一個(gè)頁面?

如何在 Pygame 中單擊并轉(zhuǎn)到另一個(gè)頁面?

慕桂英3389331 2021-09-11 10:24:13
所以我正在為學(xué)校作業(yè)編寫這段代碼,我應(yīng)該使用 pygame 并顯示一些文本。我把這些文字放在不同的頁面中,如果單擊屏幕,它將顯示下一個(gè)屏幕。這是我到目前為止所擁有的:import pygamepygame.init()pygame.font.init()# defining the screenSIZE = (1000, 700)screen = pygame.display.set_mode(SIZE)# define timeclock = pygame.time.Clock()#define buttonbutton = 0# define fontfontIntro = pygame.font.SysFont("Times New Roman",30)# define draw scenedef drawIntro(screen):    #start    if button > 0:        screen.fill((0, 0, 0))        text = fontIntro.render("Sigle click to start", 1, (255,255,255))        screen.blit(text, (300, 300, 500, 500))        pygame.display.flip()     #page1    if button == 1:        screen.fill((0, 0, 0))        text = fontIntro.render("page 1", True, (255, 255, 255))        pygame.display.flip()    #page2    if button == 1:        screen.fill((0, 0, 0))        text = fontIntro.render("page 2", True, (255, 255, 255))        screen.blit(text, (300,220,500,200))        pygame.display.flip()    #page3    if button == 1:        screen.fill((0, 0, 0))        text = fontIntro.render("page3", True, (255, 255, 255))        screen.blit(text, (200,190,500,200))        pygame.display.flip()running = Truewhile running:    for evnt in pygame.event.get():        if evnt.type == pygame.QUIT:            running = False        if evnt.type == pygame.MOUSEMOTION:            mx,my = evnt.pos            print(evnt.pos)            drawIntro(screen)pygame.quit()雖然它不起作用,有人可以幫忙嗎?!謝謝!
查看完整描述

2 回答

?
HUWWW

TA貢獻(xiàn)1874條經(jīng)驗(yàn) 獲得超12個(gè)贊

button = 0在開始時(shí)定義,但永遠(yuǎn)不要在主循環(huán)中更改其值。在你的drawIntro函數(shù)中,你檢查if button > 0if button == 1 很明顯你永遠(yuǎn)不會(huì)執(zhí)行任何這些if語句。

您需要通過調(diào)用來捕捉鼠標(biāo)按鈕pygame.mouse.get_pressed()并弄清楚如何正確切換到下一頁。

順便說一句,您也有if button == 13 次,我猜這不是您想要的,因?yàn)?code>if語句會(huì)在編寫時(shí)立即執(zhí)行,因此您的第 3 頁將立即顯示。您需要一些計(jì)數(shù)器來跟蹤下次按下鼠標(biāo)按鈕時(shí)需要顯示的頁面。


查看完整回答
反對(duì) 回復(fù) 2021-09-11
?
長風(fēng)秋雁

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()



查看完整回答
反對(duì) 回復(fù) 2021-09-11
  • 2 回答
  • 0 關(guān)注
  • 1025 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)