美好的一天,试图创建一组按钮精灵
我喜欢15个图像我需要是按钮。我有按钮与框()(框 - 看起来像这样)
class Box(pygame.sprite.Sprite):
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.Surface((35, 30))
self.image = self.image.convert()
self.image.fill((255, 0, 0))
self.rect = self.image.get_rect()
self.rect.centerx = 25
self.rect.centery = 505
self.dx = 10
self.dy = 10
我想使按钮与图像精灵一起工作。所以,我试图复制框类风格和我的图标做同样的..代码看起来像这样...
class Icons(pygame.sprite.Sprite):
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.load("images/airbrushIC.gif").convert()
self.rect = self.image.get_rect()
self.rect.x = 25
self.rect.y = 550
在main()
rect = image.get_rect()
rect.x = 25
rect.y = 550
ic1 = Icons((screen.get_rect().x, screen.get_rect().y))
screen.blit(ic1.image, ic1.rect)
pygame.display.update()
此代码的代码产生一个位置(接受1个参数,但有2个)错误或图像未被引用错误(在Icon类中)。
我不确定这是否正确的方式去反正这..反正我知道我需要加载所有的图像(如精灵)...将它们存储在一个数组中...然后让我的鼠标检查它是否使用for循环单击数组中的某个项目。
谢谢。
如果你要问一个问题,让另外一个问题。不要编辑,并期望人们回答,这不是如何工作。我将编辑你的额外问题。 –