#代码清单17-1 使用动画精灵在屏幕上放多个沙滩球图像
import sys,pygame
class MyBallClass(pygame.sprite.Sprite):
def __init__(self,image_file,location):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.load(image_file)
self.rect = self.image.get_rect()
self.rect.left,self.rect.top = location
size = width,heigh = 640,480
screen =pygame.display.set_mode(size)
screen.fill([255,255,255])
img_file = "beach_ball.png"
balls = []
for row in range (0,3):
for column in range (0,3):
location = [column *180 +10,row * 180 +10]
ball = MyBallClass(img_file,location)
balls.append(ball)
for ball in balls:
screen.blit(ball.image,ball.rect)
pygame.display.flip()
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.quit()
一起学Python 第17章 动画精灵和碰撞检测
最新推荐文章于 2021-04-17 15:45:21 发布