Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 静音和取消静音功能_Python_Python 3.x_Pygame - Fatal编程技术网

Python 静音和取消静音功能

Python 静音和取消静音功能,python,python-3.x,pygame,Python,Python 3.x,Pygame,我的主屏幕上有静音和取消静音按钮,我遇到的问题是,当我按下静音按钮时,它会变成一个取消静音按钮,然后当我玩游戏并死亡,我回到主屏幕时,它会变成一个静音按钮。我想让它,如果我静音我的游戏,我开始它和死亡,它仍然是一个静音按钮,它不会恢复到一个取消静音按钮。我也尝试过使用True和False语句 我的完整代码 导入pygame,随机 pygame.init() 宽度=500 高度=600 #屏幕宽度和高度 window=pygame.display.set_模式((宽度、高度)) #屏幕名称 pyg

我的主屏幕上有静音和取消静音按钮,我遇到的问题是,当我按下静音按钮时,它会变成一个取消静音按钮,然后当我玩游戏并死亡,我回到主屏幕时,它会变成一个静音按钮。我想让它,如果我静音我的游戏,我开始它和死亡,它仍然是一个静音按钮,它不会恢复到一个取消静音按钮。我也尝试过使用
True
False
语句

我的完整代码

导入pygame,随机
pygame.init()
宽度=500
高度=600
#屏幕宽度和高度
window=pygame.display.set_模式((宽度、高度))
#屏幕名称
pygame.display.set_标题(“游戏”)
#断断续续的音乐
music\u on=pygame.image.load(“img/music\u on.png”)
music\u on=pygame.transform.scale(music\u on,(music\u on.get\u width()//2,music\u on.get\u height()//2))
music\u off=pygame.image.load(“img/music\u off.png”)
music\u off=pygame.transform.scale(music\u off,(music\u off.get\u width()//2,music\u off.get\u height()//2))
#启动屏幕
def text_对象(字体、文本):
textSurface=font.render(文本,真,(0,0,0))
返回textSurface,textSurface.get_rect()
def按钮(消息、x、y、w、h、ac、ic、操作=无):
mouse=pygame.mouse.get_pos()
click=pygame.mouse.get_pressed()
如果鼠标[0]>x和y+h>鼠标[1]>y:
pygame.draw.rect(窗口,ac,(x,y,w,h))
如果单击[0]==1并执行操作!=无:
行动()
其他:
pygame.draw.rect(窗口,ic,(x,y,w,h))
def quitgame():
pygame.quit()
def game2():
#背景转换的一部分
#球员级别
职业球员:
定义初始值(自、x、y、宽度、高度、颜色):
self.x=x
self.y=y
self.width=宽度
自我高度=高度
self.color=颜色
self.rect=pygame.rect(x,y,宽度,高度)
def获取正确(自我):
self.rect.topleft=(self.x,self.y)
返回self.rect
def牵引(自):
self.rect.topleft=(self.x,self.y)
pygame.draw.rect(窗口,self.color,self.rect)
#按钮类
类别按钮11:
定义初始值(自身、颜色、x、y、宽度、高度、文本=“”):
self.color=颜色
self.x=x
self.y=y
self.width=宽度
自我高度=高度
self.text=文本
self.over=False
def绘图(自身、窗口、轮廓=无):
#调用此方法在屏幕上绘制按钮
如果概述:
pygame.draw.rect(窗口,轮廓(self.x-2,self.y-2,self.width+4,self.height+4),0)
pygame.draw.rect(窗口,self.color,(self.x,self.y,self.width,self.height),0)
如果self.text!='':
font=pygame.font.SysFont(“comicsans”,60)
text=font.render(self.text,1,(0,0,0))
blit(text,(self.x+(self.width/2-text.get\u width()/2),self.y+(self.height/2-text.get\u height()/2)))
def isOver(自身,位置):
#Pos是鼠标位置或(x,y)坐标的元组
如果位置[0]>self.x和位置[0]self.y和位置[1]=20:
刺激器+=1
如果刺激值>0:
刺激器+=1
对。x+=20
右2.x-=20
如果刺激值>=32:
主循环()
刺激物=
    if on:
        window.blit(music_on,(420,10))
    if off:
        window.blit(music_off,(420,10))
if ( sound_muted ):
    window.blit( music_on, (420,10) )   # show "un-mute" button
else:
    window.blit( music_off, (420,10) )  # show "mute" button
        if event.type == pygame.MOUSEBUTTONDOWN:
            pos = pygame.mouse.get_pos()
            if Sbutton.isOver(pos):
                sound_muted = not sound_muted  # mute or un-mute the sound.