|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- import pygame
- import sys
- from pygame.locals import *
- pygame.init()
- size = width, height = 640, 480
- bg = (0, 0, 0)
- clock = pygame.time.Clock()
- screen = pygame.display.set_mode(size)
- pygame.display.set_caption("FishC Demo")
- turtle = pygame.image.load("turtle.png").convert_alpha()
- background = pygame.image.load("background.jpg").convert()
- position = turtle.get_rect()
- print(position)
- #将矩形的正中心移动到屏幕的正中心
- position.center = width // 2, height // 2
- print(position)
- def blit_alpha(target, source, location, opacity):
- x = location[0]
- y = location[1]
- #convert得到的不带a通道surfeace对象,a通道表示透明度
- 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)
复制代码
blit_alpha那一块。并不是很懂。。特别是 temp.blit(target, (-x, -y )),把屏幕刷到(-x,-y)上是什么意思。。
先创建一个Scrface,把屏幕复制上去,刷上要刷上去的目标,然后补上透明度,最后把整个Surface移回来。
|
|