pygame.rect不可调用

时间:2013-07-09 15:30:45

标签: python-2.7 pygame

请帮我,我有这个代码:

import sys, pygame
pygame.init()

size = width, height = 800, 600
speed = [2, 2]
black = 1, 1, 1

screen = pygame.display.set_mode(size)

ball = pygame.image.load("ball.bmp")
ballrect = ball.get_rect()
player1 = pygame.image.load("player1.png")
player1rect = player1.get_rect()

while 1:
    for event in pygame.event.get():
        if event.type == pygame.QUIT: sys.exit()

    ballrect = ballrect.move(speed)
    if ballrect.left < 0 or ballrect.right > width:
        speed[0] = -speed[0]
    if ballrect.top < 0 or ballrect.bottom > height:
        speed[1] = -speed[1]

    player1rect = player1rect.move(speed)
    if player1rect.w < 0 or player1rect.s > heght:
        speed[1] = -speed[1]

    screen.fill(black)
    screen.blit(ball, ballrect) (player1, player1rect)
    pygame.display.flip()

当我尝试启动时,它只是说:

Traceback (most recent call last):
  File "C:\Users\User\Documents\Pong\pong.py", line 31, in <module>
    screen.blit(ball, ballrect) (player1, player1rect)
TypeError: 'pygame.Rect' object is not callable

那么有谁可以帮助我?我已经尝试了几乎所有的东西,它不会工作,如果我的代码有更多的错误,所以请写下来。

(抱歉我的英语不好)

1 个答案:

答案 0 :(得分:0)

将第31行替换为两行:

screen.blit(ball, ballrect)
screen.blit(player1, player1rect)

这应该可以解决您的问题