简体   繁体   English

它不会绘制我的矩形(prdroid 上的 pygame)

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

The screen wont fill and it says there is no fill cmd for screen, what did I do wrong?屏幕不会填充,它说屏幕没有填充 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()

There are some syntax errors in your code:您的代码中存在一些语法错误:

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

More than that, the event loop is missing.不仅如此,还缺少事件循环。 This can cause your application to freeze.这可能会导致您的应用程序冻结。 See pygame.event.get() respectively pygame.event.pump() :分别参见pygame.event.get()pygame.event.pump()

For each frame of your game, you will need to make some sort of call to the event queue.对于游戏的每一帧,您都需要对事件队列进行某种调用。 This ensures your program can internally interact with the rest of the operating system.这确保您的程序可以在内部与操作系统的 rest 进行交互。

Correct program:正确程序:

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