简体   繁体   English

调用时decisionBar() 不会将图像blit 到屏幕上

[英]decisionBar() won't blit the image to the screen when it is called

    showScreen = True
    if showScreen == True:
        display = pygame.display.set_mode((500, 200))
        pygame.display.set_caption("Decision Bar Window")
        decisionBarImage = pygame.image.load('D:/Adriel/Documents/Python stuff/Games/Basic python game/Images/decision_bar.png')
        pygame.display.flip
        display.blit(decisionBarImage, (250,100))

In my code, the window will open but the image won't blit onto it.在我的代码中,窗口将打开,但图像不会闪烁到它上面。 Please help.请帮忙。

You have to blit the image to the screen surface before calling pygame.display.flip() .在调用pygame.display.flip()之前,您必须将图像 blit 到屏幕表面。

Then you have to actually call the flip() function.然后您必须实际调用flip()函数。 In your code, the () are missing.在您的代码中,缺少()

Also, you need an event loop, otherwise your window will freeze or maybe not display anything.此外,您需要一个事件循环,否则您的窗口将冻结或可能不显示任何内容。

So your code should look like this:所以你的代码应该是这样的:

    display = pygame.display.set_mode((500, 200))
    pygame.display.set_caption("Decision Bar Window")
    decisionBarImage = pygame.image.load('D:/Adriel/Documents/Python stuff/Games/Basic python game/Images/decision_bar.png')
    display.blit(decisionBarImage, (250,100))

    while True:
        for e in pygame.event.get():
            pass # TODO: handle at least the QUIT event     

        pygame.display.flip()

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

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