class plane(pygame.sprite.Sprite):
# input the image, animate's frame and position
def __init__(self, target, frame, pos=(0, 0)):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.load(target).convert_alpha()
self.main_image = self.image
self.rect = self.image.get_rect()
self.frame = frame
self.count = 0
self.rect.topleft = pos
self.oriRect = (self.image.get_rect().width, self.image.get_rect().height)
# judge the parity of frame to zoom in and out
def update(self):
if self.count % 2 == 0:
self.count = 1
self.main_image = pygame.transform.scale2x(self.image)
else:
self.count = 0
self.main_image = pygame.transform.scale(self.image, self.oriRect)
self.image = self.main_image
pln = plane(plnjpg, 2, (100, 100))
group = pygame.sprite.Group()
group.add(pln)
while True:
screen.blit(bg, (0, 0))
group.update()
group.draw(screen)
pygame.display.update()
pygame.time.wait(500)
# delay 500ms
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
忙了半个月。终于又可以开始学了
展开