playerOnePosition = (WINDOWHEIGHT - PADDLESIZE) /2
y = 0
moveY = 0
#Creates Rectangles for ball and paddles.
paddle1 = pygame.Rect(PADDLEOFFSET,(playerOnePosition,(y)), LINETHICKNESS,PADDLESIZE)
drawPaddle(paddle2)
clock = pygame.time.Clock()
while True: #main game loop
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
# mouse movement commands
if (event.type == pygame.KEYDOWN):
if(event.key == pygame.K_DOWN):
moveY = -5
if (event.key == pygame.K_UP):
moveY = 5
if (event.type == pygame.UP):
if(event.key == pygame.K_DOWN):
moveY = 0
if (event.key == pygame.K_UP):
moveY = 0
y += moveY
clock.tick(50)
我的代码中的这部分工作不正常,我试图设置按键使拍板上下移动,但我无法弄清楚我的代码有什么问题。
错误是:Argument must be rect style object
答案 0 :(得分:0)
不起作用的一行就是这一行:
paddle1 = pygame.Rect(PADDLEOFFSET,(playerOnePosition, (y)), LINETHICKNESS,PADDLESIZE)
Rect
expects four (or two, or one) parameters:
class pygame.Rect
用于存储直角坐标的pygame对象
Rect(left, top, width, height) -> Rect
Rect((left, top), (width, height)) -> Rect
Rect(object) -> Rect
所以PADDLEOFFSET
为left
,LINETHICKNESS
为width
,PADDLESIZE
为height
。
但对于top
,您有(playerOnePosition, (y))
,这是一个元组,而不是Rect
所期望的整数。将其更改为整数,它将起作用。
Argument must be rect style object
是Rect
类在参数类型错误时引发的一般错误消息。