鱼C论坛

 找回密码
 立即注册
查看: 2546|回复: 2

[已解决]小甲鱼的飞机大战

[复制链接]
发表于 2021-3-18 13:51:21 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
在添加暂停按钮时 当大飞机飞来时按下暂停 大飞机的飞行音效无法暂停
还有就是想让背景音乐同时暂停该怎么做
求大神指点指点
最佳答案
2021-3-18 14:26:40
本帖最后由 小伤口 于 2021-3-18 14:55 编辑

小甲鱼不是有一个paused的变量来判断是否游戏暂停吗


在小甲鱼判断鼠标是否位于暂停按钮的那段代码
大概是这个位置
  1. elif event.type==MOUSEBUTTONDOWN:
  2.                 #collidepoint检测鼠标是否位于矩形内是就返回True
  3.                 if event.button==1 and paused_rect.collidepoint(event.pos):
  4.                     if not paused:
  5.                         paused_image=resume_pressed_image
  6.                     else:
  7.                         paused_image=pause_pressed_image
复制代码

在里面加一个
  1. if paused:
  2.     pygame.time.set_timer(SUPPLY_TIME,0)
  3.     pygame.mixer.music.pause()
  4.     pygame.mixer.pause()
  5.    
  6. else:
  7.     pygame.time.set_timer(SUPPLY_TIME,30*1000)
  8.     pygame.mixer.music.unpause()
  9.     pygame.mixer.unpause()
复制代码

也就是这样
  1. elif event.type==MOUSEBUTTONDOWN:
  2.     #collidepoint检测鼠标是否位于矩形内是就返回True
  3.     if event.button==1 and paused_rect.collidepoint(event.pos):
  4.         if not paused:
  5.             paused_image=resume_pressed_image
  6.         else:
  7.             paused_image=pause_pressed_image
  8.         
  9.         

  10.         paused=not paused
  11.     if paused:
  12.         pygame.time.set_timer(SUPPLY_TIME,0)
  13.         pygame.mixer.music.pause()
  14.         pygame.mixer.pause()
  15.         
  16.     else:
  17.         pygame.time.set_timer(SUPPLY_TIME,30*1000)
  18.         pygame.mixer.music.unpause()
  19.         pygame.mixer.unpause()
复制代码

如果有帮助的话请设置最佳吧
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2021-3-18 14:26:40 | 显示全部楼层    本楼为最佳答案   
本帖最后由 小伤口 于 2021-3-18 14:55 编辑

小甲鱼不是有一个paused的变量来判断是否游戏暂停吗


在小甲鱼判断鼠标是否位于暂停按钮的那段代码
大概是这个位置
  1. elif event.type==MOUSEBUTTONDOWN:
  2.                 #collidepoint检测鼠标是否位于矩形内是就返回True
  3.                 if event.button==1 and paused_rect.collidepoint(event.pos):
  4.                     if not paused:
  5.                         paused_image=resume_pressed_image
  6.                     else:
  7.                         paused_image=pause_pressed_image
复制代码

在里面加一个
  1. if paused:
  2.     pygame.time.set_timer(SUPPLY_TIME,0)
  3.     pygame.mixer.music.pause()
  4.     pygame.mixer.pause()
  5.    
  6. else:
  7.     pygame.time.set_timer(SUPPLY_TIME,30*1000)
  8.     pygame.mixer.music.unpause()
  9.     pygame.mixer.unpause()
复制代码

也就是这样
  1. elif event.type==MOUSEBUTTONDOWN:
  2.     #collidepoint检测鼠标是否位于矩形内是就返回True
  3.     if event.button==1 and paused_rect.collidepoint(event.pos):
  4.         if not paused:
  5.             paused_image=resume_pressed_image
  6.         else:
  7.             paused_image=pause_pressed_image
  8.         
  9.         

  10.         paused=not paused
  11.     if paused:
  12.         pygame.time.set_timer(SUPPLY_TIME,0)
  13.         pygame.mixer.music.pause()
  14.         pygame.mixer.pause()
  15.         
  16.     else:
  17.         pygame.time.set_timer(SUPPLY_TIME,30*1000)
  18.         pygame.mixer.music.unpause()
  19.         pygame.mixer.unpause()
复制代码

如果有帮助的话请设置最佳吧
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

 楼主| 发表于 2021-3-18 17:47:20 | 显示全部楼层
对的  它在下节课讲的 当时还没看下节课的
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-6-26 13:44

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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