繁体   English   中英

Python初学者碰撞检测问题

[英]Python Beginner Collision Detection Problems

我是编码的初学者,并且正在从事基本的平台游戏。 在过去的几天里,我查看了许多不同的资源,但并没有一个清晰的画面。 在这一点上,我很迷茫,无法在一个人的方法与另一个人的方法之间进行切换。 现在,我正在看这个Pygame tut 我收到以下错误:

  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

代码如下:

    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)

为什么会给出错误?

不熟悉pygame,但是文档说 rect应该大写,例如pygame.Rect(32, 32, 16, 16) -试试看。

该方法使用大写字母R而不是小写字母r

self.rect = pygame.Rect(32, 32, 16, 16) # capital `R`

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM