python - 我的 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, 0))
pygame.display.update()
pygame.quit()
解决方案
rect
函数至少需要三个参数,只给出了 2 个:
pygame.draw.rect(win, (255, 0, 0), (x, y, width, height))
它也应该在mac上工作
检查 pygame 文档以供参考:https ://www.pygame.org/docs/ref/draw.html#pygame.draw.rect
推荐阅读
- android - 检查房间数据库中的日期是否大于今天
- javascript - 在预定义的非线性位置上排列图标
- c# - SMTP 未正确发送我的电子邮件
- accessibility - 可访问性 p 为屏幕阅读器标记不同的文本
- c++ - 有什么方法可以让我的二分搜索算法更有效,而且,它是否正确?
- python - solvepnp 是否给出了相对于对象的相机位置绝对相机位置?
- kotlin - Spring Cloud Custom GatewayFilter - 使用过滤器内另一个客户端请求的结果修改响应 POST 过滤器
- c# - Visual Studio 未从 Microsoft SQL Server Management Studio 加载数据
- python - 在 python 上订购带有字典的列表
- python - 在 pandas 中使用 apply 迭代后缀