| 
 | 
 
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册  
 
x
 
- import pygame
 
 - import sys
 
 - from pygame.locals import *
 
 - #这里把position = position.move(speed)放到判断图片到达边界的两个if语句后面,
 
 - #就可以避免出现BUG
 
  
- pygame.init()
 
  
 
- size = width,height = 600,400
 
 - bg = (255,255,255)
 
 - speed =[2,-1]
 
  
- clock = pygame.time.Clock()
 
  
- screen = pygame.display.set_mode(size,RESIZABLE)
 
  
- pygame.display.set_caption('你好呀 我是赛利亚')
 
  
- ratio = 1.0 #设置放大缩小比率
 
  
- oball = pygame.image.load('ball.jpg')
 
 - ball = oball
 
 - oball_rect = ball.get_rect()
 
 - position = ball_rect=oball_rect
 
 - #全屏设置
 
 - fullscreen = False
 
 - list_srcrren=pygame.display.list_modes()
 
  
- orient = 1#解决缩放的调头的BUG参数
 
 - l_head = ball
 
 - r_head = pygame.transform.flip(ball,True,False)#水平翻转的图像
 
  
- while True:
 
 -     for event in pygame.event.get():
 
 -         #用户调整窗口尺寸
 
 -         if event.type == VIDEORESIZE and not fullscreen:
 
 -             size = event.size
 
 -             width,height = size
 
 -             print(size)
 
 -             screen = pygame.display.set_mode(size,RESIZABLE)
 
 -             #又是靠复位解决BUG没有按比例来重现位置
 
 -             if position.left <0 or position.right>width:
 
 -                position = ball.get_rect()
 
 -             if position.top <0 or position.bottom>height:
 
 -                position = ball.get_rect()
 
 -         if event.type == QUIT:
 
 -             sys.exit()
 
 -         if event.type == KEYDOWN:
 
 -             if event.key == K_LEFT:
 
 -                 speed = [-1,0]
 
 -    
 
 -                 ball = l_head
 
 -   
 
 -             if event.key == K_RIGHT:
 
 -                 speed = [1,0]
 
  
-                 ball = r_head
 
  
-             if event.key == K_UP:
 
 -                 speed = [0,-1]
 
 -             if event.key == K_DOWN:
 
 -                 speed = [0,1]
 
 -             if event.key ==K_EQUALS or event.key == K_MINUS or event.key == K_SPACE:
 
 -                 if event.key == K_EQUALS and ratio < 2:
 
 -                     if orient == -1:
 
 -                         ratio += 0.1
 
 -                         ball = pygame.transform.flip(ball,True,False)
 
 -                     else:
 
 -                         ratio += 0.1
 
 -                 if event.key == K_MINUS and ratio > 0.5:
 
 -                     if orient == -1:
 
 -                         ratio -= 0.1
 
 -                         ball = pygame.transform.flip(ball,True,False)
 
 -                         
 
 -                     else:
 
 -                         ratio -= 0.1
 
 -                 if event.key == K_SPACE:
 
 -                     ratio = 1.0
 
  
-                 ball=pygame.transform.smoothscale(oball,(int(oball_rect.width * ratio),\
 
 -                                              int(oball_rect.height * ratio)))
 
 -                 l_head  = ball
 
 -                 r_head = pygame.transform.flip(ball,True,False)
 
 -             if event.key == K_F11:
 
 -                 fullscreen = not fullscreen
 
 -                 if fullscreen:
 
 -                     
 
 -                     screen = pygame.display.set_mode(list_srcrren[1],\
 
 -                     FULLSCREEN|HWSURFACE)
 
 -                     size=width,height=list_srcrren[1][0],list_srcrren[1][1]
 
 -                 else:
 
 -                     position = ball.get_rect()
 
 -                     #按下F11时复位 解决了反复横跳 但理想方法是根据比例还原位置才对
 
 -                     size = width,height = 600,400
 
 -                     screen = pygame.display.set_mode(size)
 
 -     #position = position.move(speed) 放if前面会有一直按'下'会卡进边缘里面BUG
 
 -     if position.left <0 or position.right>width:
 
 -         #翻转图像
 
  
-         ball = pygame.transform.flip(ball,True,False)
 
 -         speed[0] = -speed[0]
 
 -     if position.top <0 or position.bottom>height:
 
 -         speed[1] = -speed[1]
 
 -         
 
 -     position = position.move(speed)
 
 -     #填充背景    
 
 -     screen.fill(bg)
 
 -     #更新图像
 
 -     screen.blit(ball,position)
 
 -     #更新界面
 
 -     pygame.display.flip()
 
 -     #延迟10毫秒
 
 -     pygame.time.delay(10)
 
  复制代码 
 
放大缩小时会复位,所以会改变方向,请问下各位这个BUG如何解决 
弹幕说在缩放前加个判断 若放缩前orient = -1, 则对放缩后图片进行水平翻转,否则方向不做改变。 
但我没有修改成功  麻烦大佬们解答了 |   
 
 
 
 |