簡體   English   中英

它不會繪制我的矩形(prdroid 上的 pygame)

[英]It wont draw my rectangle (pygame on prdroid)

屏幕不會填充,它說屏幕沒有填充 cmd,我做錯了什么?

import pygame
    
pygame.init()

screen = pygame.display
set_mode((0, 0))

white = (255, 255, 255)
Square =(0, 0, 0)

loop = True
while loop:
    screen.fill(white)
    pygame.draw.rect(screen, Square, pygame)Rect(100, 100, 200, 200)
    pygame.display.update()

您的代碼中存在一些語法錯誤:

screen = pygame.display
set_mode((0, 0))

screen = pygame.display.set_mode((0, 0))

pygame.draw.rect(screen, Square, pygame)Rect(100, 100, 200, 200)

pygame.draw.rect(screen, Square, pygame.Rect(100, 100, 200, 200))

不僅如此,還缺少事件循環。 這可能會導致您的應用程序凍結。 分別參見pygame.event.get()pygame.event.pump()

對於游戲的每一幀,您都需要對事件隊列進行某種調用。 這確保您的程序可以在內部與操作系統的 rest 進行交互。

正確程序:

import pygame
    
pygame.init()
screen = pygame.display.set_mode((640, 480))

white = (255, 255, 255)
Square = (0, 0, 0)

loop = True
while loop:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            loop = False

    screen.fill(white)
    pygame.draw.rect(screen, Square, pygame.Rect(100, 100, 200, 200))
    pygame.display.update()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM