|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
现在我的问题是,点鼠标,图片在离鼠标很远的地方播放。我想把播放的图片中心点求出来,然后让鼠标的位置减去图片中心的位置,但是提示元祖不能减元祖。
- import pygame
- import sys
- from pygame.locals import *
- pygame.init()
- size = width, height = 512, 768
- screen = pygame.display.set_mode(size)
- pygame.display.set_caption("a")
- tip=0
- water_num=0
- mask_num=0
- img_list=[]
- water_list=[]
- #mask_list=[]
- select=0
- mouse_pos=0
- clock=pygame.time.Clock()
- fullscreen=False
- for i in range(1,10):
- img=pygame.image.load("ground_"+str(i)+".jpg").convert()
- img_list.append(img)
- for a in range(1,10):
- water=pygame.image.load("water\water_a_"+str(a)+".png").convert_alpha()
- water_list.append(water)
- position=water_list[water_num].get_rect()
- position_center=position.width//2,position.height//2
- #for m in range(1,275):
- #mask=pygame.image.load("mask\mask_a_"+str(m)+".png").convert_alpha()
- #mask_list.append(mask)
- 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)
- """def mask_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 == pygame.QUIT:
- sys.exit()
- if event.type==KEYDOWN:
- if event.key==K_F11:
- fullscreen=not fullscreen
- if fullscreen:
- screen=pygame.display.set_mode((1920,1080),FULLSCREEN|HWSURFACE)
- else:
- screen=pygame.display.set_mode(size)
- if event.type==MOUSEBUTTONDOWN:
- if event.button==1:
- select=1
-
- if event.type==MOUSEBUTTONUP:
- if event.button==1:
- select=0
- [color=Red]position_water=pygame.mouse.get_pos()-position.center[/color]
- #position_mask=pygame.mouse.get_pos()
- position_img=img_list[tip].get_rect()
- screen.blit(img_list[tip],position_img)
- if select:
- blit_alpha(screen,water_list[water_num],position_water,255)
- #mask_alpha(screen,mask_list[mask_num],position_mask,255)
- else:
- screen.blit(img_list[tip],position_img)
-
-
-
-
- #screen.blit(water_list[water_num],position_water)`
-
- pygame.display.flip()
- tip=0
- water_num=0
- #(water_num+1)%274
- #mask_num=(mask_num+1)%274
- clock.tick(30)
-
复制代码 |
|