|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
之前听的时候没有弄清楚blit_alpha中的temp.blit(target,(-x,-y)), target 是背景,明明比temp的窗口要大,为什么第二个参数是(-x,-y) ? 我试了下第二个参数用(x,y) 或者 (0,0), 甚至直接把 x=position[0] y=position[1] temp.blit(target,(-x,-y))
这三句删掉,感觉效果都没有区别。。。谁能告知有什么区别吗? 是pygame模块升级了吗?确实有点没看懂 temp.blit(target,(-x,-y)) 的意义,求助,谢谢~~
- import pygame
- import sys
- from pygame.locals import *
- #pygame initionization
- pygame.init()
- size=width,height=800,600
- bg=0,0,0
- clock=pygame.time.Clock()
- #window create
- screen=pygame.display.set_mode(size)
- #window title
- pygame.display.set_caption("First time to meet, take care of me!")
- turtle=pygame.image.load('turtle.png').convert_alpha()
- background=pygame.image.load('background.jpg').convert()
- position=turtle.get_rect()
- position.center=width//2,height//2
- def blit_alpha(target,source,location,opacity):
- temp=pygame.Surface((source.get_width(),source.get_height())).convert()
- x=position[0]
- y=position[1]
- 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)
复制代码
-x,-y是考虑你的背景,为了让王八在0,0
背景相对位置不变,所以跑到-想,-x,-y
|
|