zhudaming120 发表于 2020-4-26 16:04:17

请教错误在哪,按空格图片变化,音乐不会停止

import pygame
import sys
from pygame.locals import *

pygame.init()
pygame.mixer.init()

pygame.mixer.music.load("F:\工程\python\Battle02.mid")
pygame.mixer.music.set_volume(0.2)
pygame.mixer.music.play()


cat_sound = pygame.mixer.Sound("F:\工程\python\System02.ogg")
cat_sound.set_volume(0.2)



bg_size = width,height = 300,200
screen = pygame.display.set_mode(bg_size)
pygame.display.set_caption("音乐音效试水")

pause = False

pause_image = pygame.image.load("F:\工程\python\icon.png").convert_alpha()
unpause_image = pygame.image.load("F:\工程\python\Fighter01.png").convert_alpha()
pause_rect = pause_image.get_rect()
#图片放置于正中心
pause_rect.left,pause_rect.top = (width - pause_rect.width)//2,(height - pause_rect.height)//2

clock = pygame.time.Clock()


while True:
    for event in pygame.event.get():
      if event.type == QUIT:
            sye.exit()


      if event.type == MOUSEBUTTONDOWN:
            if event.button == 1:
                cat_sound.play()

      if event.type == KEYDOWN:
            if event.key == K_SPACE:
                pause = not pause
               
    screen.fill((255,255,255))



    if pause:
      screen.blit(pause_image,pause_rect)
      pygame.mixer.music.pause()
    else:
      screen.blit(unpause_image,pause_rect)
      pygame.mixer.music.unpause()
      
    pygame.display.flip()
   
    clock.tick(10)

老八秘制 发表于 2020-4-26 16:29:28

你们这些基本上都是代码粗心打错了,自己检查一遍,用的图片和小甲鱼的一不一样

zhudaming120 发表于 2020-4-26 16:53:56

用的是自己音乐,查了好几次代码,没发现错误{:10_249:},跟音乐格式有关系吗?

wuqramy 发表于 2020-4-26 17:11:29

zhudaming120 发表于 2020-4-26 16:53
用的是自己音乐,查了好几次代码,没发现错误,跟音乐格式有关系吗?

没关系的
页: [1]
查看完整版本: 请教错误在哪,按空格图片变化,音乐不会停止