surface整体透明度测试程序_pygame whole alpha test program

"""
   surface整体透明度测试程序.py
   用surface的set_alpha设定透明度。
   这种情况的透明度只能给图像设置一个整体透明度。
   不象每像素透明度设置那样可以精确到每一个像素的a值来给图像设置透明度。
   pygame the full Surface alpha test program  by lixingqiu
"""
import pygame
from random import randint
from pygame.locals import *
    
screen = pygame.display.set_mode((480,360))
pygame.display.set_caption("surface整体透明度测试程序 www.lixingqiu.com")

# ultraman做为背景
ultraman = pygame.image.load('ultraman.png').convert()
earth = pygame.image.load("earth.png").convert()
width2 = earth.get_width()//2
height2 = earth.get_height()//2
earth.set_alpha(127)    # 就是此代码给图像设置整体透明度

running = True
while running:
    for event in pygame.event.get():
        if event.type == QUIT : running = False

    ms = pygame.mouse.get_pos()
    center = ms[0] - width2,ms[1] - height2
    
    screen.blit(ultraman,(0,0))   # 奥特曼做为背景
    screen.blit(earth,center)     # 地球做为前景(全体半透明)
    pygame.display.update()

pygame.quit()