I'm a beginner at coding and I'm working on a basic platformer game. I've looked at many different resources for the past couple of days and cant quite get a clear picture. At this point I'm pretty lost from switching between one person's method to another person's. Right now, I'm looking at this Pygame tut . I'm getting the following error:
File ".../PlayerPlat.py", line 87, in <module>
hero = Player(400, 0)
File ".../PlayerPlat.py", line 10, in __init__
self.rect = pygame.rect(32, 32, 16, 16)
TypeError: 'module' object is not callable
Code is as follows:
class Player(pygame.sprite.Sprite):
def __init__(self, dx, dy):
self.rect = pygame.rect(32, 32, 16, 16)
self.image = pygame.image.load("hero.png")
self.image.set_colorkey(white)
def move(self, dx, dy):
if dx!=0:
self.move_single_axis(dx, 0)
if dy!=0:
self.move_single_axis(0,dy)
def move_single_axis(self, dx, dy):
self.rect.x +=dx
self.rect.y +=dy
hero = Player(400, 0)
Why is this giving the error?
不熟悉pygame,但是文档说 rect
应该大写,例如pygame.Rect(32, 32, 16, 16)
-试试看。
该方法使用大写字母R而不是小写字母r
self.rect = pygame.Rect(32, 32, 16, 16) # capital `R`
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.