如何解决我的 pygame 窗口不断崩溃,我正在 mac 上关注 youtube 教程
我对 python 非常陌生,我一直在关注 Tech With Tim 的 pygame 教程,但我的窗口没有响应或关闭。我使用的是 mac,我不知道这是否会改变任何东西......而且我不断收到错误消息
错误:
function missing required argument 'rect' (pos 3)
。
代码:
import pygame
pygame.init()
win = pygame.display.set_mode((500,500))
pygame.display.set_caption("First game")
x = 50
y = 50
width = 40
height = 60
vel = 5
run = True
while run:
pygame.time.delay(100)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT]:
x -= vel
if keys[pygame.K_RIGHT]:
x += vel
if keys[pygame.K_UP]:
y -= vel
if keys[pygame.K_DOWN]:
y += vel
pygame.draw.rect(win,(255,0))
pygame.display.update()
pygame.quit()
解决方法
rect
函数至少接受三个参数,只给出了 2 个:
pygame.draw.rect(win,(255,0),(x,y,width,height))
它应该也适用于 mac
查看 pygame 文档以供参考:https://www.pygame.org/docs/ref/draw.html#pygame.draw.rect
,实际上您还没有输入绘制矩形的高度宽度 x 位置和 y 位置,请执行此操作
{
"Version": "2012-10-17","Statement": [
{
"Effect": "Allow","Action": [
"logs:CreateLogGroup","logs:CreateLogStream","logs:PutLogEvents"
],"Resource": "arn:aws:logs:*:*:*"
},{
"Effect": "Allow","Action": [
"ec2:DescribeSecurityGroups","ec2:AuthorizeSecurityGroupIngress","ec2:RevokeSecurityGroupIngress"
],"Resource": "*"
}
]
}
您已经定义了 pygame.draw.rect(win,height,width))
、x
、y
、height
这应该可以工作。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。