|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- #创建透明的乌龟
- import pygame
- import sys #退出程序时要用
- from pygame.locals import *
- pygame.init()
- size= width,height = 600,600
- bg=(0,0,0) #背景填充
- clock = pygame.time.Clock()
- screen=pygame.display.set_mode(size,RESIZABLE)
- pygame.display.set_caption("隐身")
- #convert_alpha,想用a通道,就用它转换图片格式,否则只用convert,即可表示透明度,a通道,0表示完全透明,255表示完全不透明
- #convert,表示将图片的像素格式转换为与背景图像相同
- turtle=pygame.image.load("turtle.png").convert_alpha()
- background = pygame.image.load("background.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))
- blit_alpha(screen,turtle,position,200)
- pygame.display.flip()
- clock.tick(30)
-
复制代码
|
|