繁体   English   中英

没有绘制Pygame矩形

[英]Pygame rectangle isn't being drawn

当我运行代码时,它不会显示任何错误。 矩形只是没有出现。 怎么能修好?

负责的函数是render() ,其行为pygame.draw.rect(win, (0, 0, 0), (100, 100, 50, 50))

import pygame

w, h = 1000, 600
caption = "Game"
background = (255, 255, 255)
running = True
clock = pygame.time.Clock()
FPS = 60

win = pygame.display.set_mode((w, h))
pygame.display.set_caption(caption)


def start():
    # This function runs only once at the start of the game
    pass


def logic():
    # This function runs every frame. This function contains the game's logic.
    pass


def render():
    # This function runs every frame. This function contains code for drawing
    # everything to the screen.
    pygame.draw.rect(win, (0, 0, 0), (100, 100, 50, 50))


def main():
    global running
    start()

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

        logic()
        win.fill(background)
        render()
        pygame.display.update()


if __name__ == "__main__":
    main()
    pygame.quit()
    quit()

抱歉打扰每个人。 我使用Atom编写并运行此代码,但每次我在Atom中使用script包运行此代码时,它都会显示一个空白屏幕。 解决方案是使用build-python包(它是一个有效的包,而不是script )。 对不起,我应该更具体一点。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM