亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

矩形未在屏幕上繪制

矩形未在屏幕上繪制

慕村9548890 2023-03-22 16:29:57
下面的代碼是創建一個按鈕,當光標懸停在它上面時它會改變顏色,同時結束程序,如果它被點擊。結果不顯示按鈕,只顯示背景。我在底部有執行后 pygame 窗口的圖像。'''# initialisingimport pygame, syspygame.init()HEIGHT = 720WIDTH  = 720screen = pygame.display.set_mode((HEIGHT,WIDTH))# colour WHITE  = (255,255,255)BLACK  = (0,  0  ,0  )MAROON = (128,0  ,0  )RED    = (255,0  ,0  )x, y = pygame.mouse.get_pos()# rendering a text written in # this font # defining a font smallfont = pygame.font.SysFont('Corbel',35) text = smallfont.render('quit' , True , BLACK)         # superimposing the text onto our button screen.blit(text,(WIDTH/2 +50, HEIGHT/2)) # describing the processwhile True:    for ev in pygame.event.get():                if ev.type == pygame.QUIT:            pygame.quit()        #describing events        if ev.type == pygame.MOUSEBUTTONDOWN:                        if WIDTH/2 -70 <= x <= WIDTH/2 + 70 and HEIGHT/2 -70 <= x <= HEIGHT/2 + 70:                pygame.quit()                pygame.display.flip()            if  WIDTH/2 -70 <= x <= WIDTH/2 + 70 and HEIGHT/2 -70 <= x <= HEIGHT/2 + 70:        pygame.draw.rect(screen,RED,(100,100,500,500))     else:        pygame.draw.rect(screen,MAROON,(100,100,500,500))                      # filling screen with colour    screen.fill(WHITE)         # updates the frames of the game     pygame.display.update()         我試過 pygame.display.flip(),改變矩形的位置,但問題沒有解決。我是 pygame 的初學者,因此才剛剛開始。
查看完整描述

1 回答

?
qq_花開花謝_0

TA貢獻1835條經驗 獲得超7個贊

您必須先繪制矩形screen.fill(WHITE)。注意pygame.Surface.fill用純色填充整個表面。之前繪制的所有內容都被覆蓋了。

# describing the process

while True:

? ? # [...]


? ? # filling screen with colour

? ? screen.fill(WHITE)


? ? if? WIDTH/2 -70 <= x <= WIDTH/2 + 70 and HEIGHT/2 -70 <= x <= HEIGHT/2 + 70:

? ? ? ? pygame.draw.rect(screen,RED,(100,100,500,500))?

? ? else:

? ? ? ? pygame.draw.rect(screen,MAROON,(100,100,500,500))

? ??

? ? # updates the frames of the game?

? ? pygame.display.update()?


查看完整回答
反對 回復 2023-03-22
  • 1 回答
  • 0 關注
  • 148 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號