我试图在图像中加载我在Pygame中编写的一个课程,问题是每当我尝试加载它时,它只是作为透明图像出现,但是对象仍然像碰撞检测。我绘制矩形的原始代码是......
class Wall:
def __init__(self, colour, x, y, size):
self.colour = colour
self.x = x
self.y = y
self.size = size
pygame.draw.rect(screen, (self.colour), (self.x, self.y, self.size, self.size))
def update(self):
pygame.draw.rect(screen, (self.colour), (self.x, self.y, self.size, self.size))
我试图改为......
class Wall(pygame.sprite.Sprite):
def __init__(self, x, y):
pygame.sprite.Sprite.__init__
self.x = x
self.y = y
Wall.image = pygame.image.load(resources + "Wall.png").convert()
self.image = Wall.image
self.rect = self.image.get_rect()
self.rect.topleft = ([x,y])
def update():
screen.blit(self.image, self.rect)
我还在加载其他类,但他们使用的是draw,而不是图像。
任何人都可以发现我装错了吗? 资源只是图像的路径,c:/ users /..../ coursework / sprites /