微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

为什么我的矩形不显示python 3.8 windoes 7

如何解决为什么我的矩形不显示python 3.8 windoes 7

我尝试复制游戏,但矩形(这是我需要的基本形状)没有出现。我做错了什么还是只是 pygame 发疯了?

代码

# importing modules
import pygame
import sys
import random

# starting pygame
pygame.init()
# making a screen
(width,height) = (500,500)
screen = pygame.display.set_mode((width,height))
pygame.display.set_caption('Mincraft')
running = True
# fps counter
clock = pygame.time.Clock()
print(clock)
# geting the x button to work
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
            pygame.display.update()
pygame.display.quit()
pygame.quit()
exit()
# colors
white = (255,255,255)
blue = (0,255)
red = (255,0)
green = (4,0)

# cube
if running == True:
    pygame.draw.rect(screen,blue,(395,10,10)),pygame.draw.rect(screen,20,clock.tick(60)

还有我将如何使它成为空的和 3d 的。我知道我要求很多,但我相信有人可以解释

解决方法

您必须在应用程序循环中绘制场景:

# importing modules
import pygame
import sys
import random

# colors
white = (255,255,255)
blue = (0,255)
red = (255,0)
green = (4,0)

# starting pygame
pygame.init()
# making a screen
(width,height) = (500,500)
screen = pygame.display.set_mode((width,height))
pygame.display.set_caption('Mincraft')
running = True
# fps counter
clock = pygame.time.Clock()
print(clock)
# geting the x button to work
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
            
    pygame.draw.rect(screen,blue,(395,10,10))
    pygame.draw.rect(screen,20,10))
    pygame.display.update()
    clock.tick(60)

pygame.display.quit()
pygame.quit()
exit()

典型的 PyGame 应用程序循环必须:

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。