group问题
import pygameimport sys
from pygame.locals import *
class Brick:
def __init__(self,position):
self.image=pygame.image.load('./material/brick.png').convert_alpha()
self.position=position
self.image_rect=self.image.get_rect()
self.image_rect.left,self.image_rect.top=self.position,self.position
def main():
pygame.init()
size=width,height=800,600
screen=pygame.display.set_mode(size)
bg_c=(255,255,255)
ball_image=pygame.image.load('./material/rainbowball.png').convert_alpha()
clock=pygame.time.Clock()
group=pygame.sprite.Group()
running=True
bricks=[]
while running:
for event in pygame.event.get():
if event.type==pygame.QUIT:
pygame.quit()
sys.exit()
for i in range(10):
for j in range(3):
brick=Brick((80*i,40*j))
bricks.append(brick)
group.add(brick)
screen.fill(bg_c)
for i in bricks:
screen.blit(i.image,i.image_rect)
pygame.display.flip()
clock.tick(60)
if __name__=='__main__':
main()
想做个打砖块,结果一开始就报错了,求解{:10_277:}
Brick类的定义改成这样:
class Brick(pygame.sprite.Sprite):
def __init__(self,position):
pygame.sprite.Sprite.__init__(self)
self.image=pygame.image.load('./material/brick.png').convert_alpha()
self.position=position
self.image_rect=self.image.get_rect()
self.image_rect.left,self.image_rect.top=self.position,self.position
页:
[1]