鱼C论坛

 找回密码
 立即注册
查看: 2286|回复: 4

小甲鱼pygame81讲中退出全屏BUG,求解

[复制链接]
发表于 2022-5-22 10:51:39 | 显示全部楼层
有点忘了, 应该可以检测点击全屏和退出全屏的按钮, 提供一个思路, 我记得是可行的
  1. if 全屏按钮:
  2.     if 全屏状态:
  3.         重置小乌龟位置
  4.         重置游戏框大小
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-5-23 12:13:50 | 显示全部楼层
这是我以前写的, 你参考一下

  1. import pygame
  2. import sys
  3. from pygame.constants import *


  4. def change_pos(position, width, height):
  5.     if position.right > width:
  6.         position.right = width
  7.                     
  8.     if position.bottom > height:
  9.         position.bottom = height

  10. pygame.init()
  11. # size = width, height = (600, 400)
  12. size = width, height = (1536, 864)
  13. speed = [5, 0]
  14. bg = (255, 255, 255)
  15. clock = pygame.time.Clock()
  16. screen = pygame.display.set_mode(size, RESIZABLE)
  17. pygame.display.set_caption("初次见面,请多多关照!")
  18. # post the turtle
  19. turtle = pygame.image.load(r"D:\user\Desktop\pyPractice\game\turtle\turtle.png").convert_alpha()
  20. position = turtle.get_rect()

  21. for i in range(position.width):
  22.     for j in range(position.height):
  23.         at = turtle.get_at((i, j))
  24.         if at[0] > 100 and at[2] > 200 and at[1] > 100:
  25.             at[3] = 0
  26.         turtle.set_at((i, j),at)

  27. turtle_right = pygame.transform.rotate(turtle, 90)
  28. turtle_top = pygame.transform.rotate(turtle, 90*2)
  29. turtle_left = pygame.transform.rotate(turtle, 90*3)
  30. turtle_bottom = turtle
  31. turtle = turtle_top
  32. fullscreen = False
  33. while True:
  34.     for event in pygame.event.get():
  35.         if event.type == pygame.QUIT:
  36.             sys.exit()
  37.         
  38.         if event.type == VIDEORESIZE:
  39.             if (event.size[0] < 200):
  40.                 event.size = (200, event.size[1])
  41.                 size = event.size
  42.                 width, height = size
  43.                 screen = pygame.display.set_mode(size, RESIZABLE)
  44.                 change_pos(position, width, height)
  45.             
  46.             if (event.size[1] < 200):
  47.                 event.size = (event.size[0], 200)
  48.                 size = event.size
  49.                 width, height = size
  50.                 screen = pygame.display.set_mode(size, RESIZABLE)
  51.                 change_pos(position, width, height)
  52.             else:   
  53.                 size = event.size
  54.                 width, height = size
  55.                 screen = pygame.display.set_mode(size, RESIZABLE)
  56.                 change_pos(position, width, height)

  57.         if event.type == KEYDOWN:   
  58.             if event.key == pygame.K_F11:
  59.                 fullscreen = not fullscreen
  60.                 if fullscreen:
  61.                     # size = width, height = pygame.display.list_modes()[0]
  62.                     size = width, height = (1536, 864)
  63.                     screen = pygame.display.set_mode(size, pygame.HWSURFACE)

  64.                 else:
  65.                     size = width, height = (600, 400)
  66.                     screen = pygame.display.set_mode(size)
  67.                     change_pos(position, width, height)

  68.     position = position.move(speed)
  69.     if position.right > width:
  70.         turtle = turtle_right
  71.         position = turtle_rect = turtle.get_rect()
  72.         position.right = width
  73.         speed = [0, 5]

  74.     if position.bottom > height:
  75.         turtle = turtle_bottom
  76.         position = turtle_rect = turtle.get_rect()
  77.         position.right = width
  78.         position.bottom = height
  79.         speed = [-5, 0]
  80.    
  81.     if position.left < 0:
  82.         turtle = turtle_left
  83.         position = turtle_rect = turtle.get_rect()
  84.         position.bottom = height
  85.         speed = [0, -5]
  86.    
  87.     if position.top < 0:
  88.         turtle = turtle_top
  89.         position = turtle_rect = turtle.get_rect()
  90.         speed = [5, 0]

  91.     screen.fill(bg)
  92.     screen.blit(turtle, position)
  93.     pygame.display.flip()
  94.     pygame.time.delay(10)
  95.     clock.tick(200)


复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-9-26 03:01

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表