import pygame import sys # 退出需要 from pygame.locals import * pygame.init() # 初始化 size = width, height = 600, 385 # 设置窗口尺寸 bg = (0, 0, 0) # 背景颜色 clock = pygame.time.Clock() # 设置帧率需要 screen = pygame.display.set_mode(size) # 设置窗口 pygame.display.set_caption("Python Demo") # 设置窗口名 turtle = pygame.image.load("18.gif").convert_alpha() # .convert可尽可能高效的处理图片 background = pygame.image.load("17.png").convert() position = turtle.get_rect() # 获取乌龟位置 position.center = width // 2, height // 2 # 获取乌龟中心位置 ############################################################# def blit_alpha(target, source, location, opacity): x = location[0] y = location[1] temp = pygame.Surface((source.get_width(), source.get_height())).convert() temp.blit(target, (-x, -y)) temp.blit(source, (0, 0)) temp.set_alpha(opacity) target.blit(temp, location) ############################################################# while True: for event in pygame.event.get(): if event.type == QUIT: sys.exit() screen.blit(background, (0, 0)) ############################################################ # screen.blit(turtle, position) blit_alpha(screen, turtle, position, 200) ############################################################ pygame.display.flip() clock.tick(30)