Вопрос

I'm making a program which when the player dies, gets the music time, and plays a new song using the music time from the previous song, I've done this before a while back and it worked with no problems, but now it's giving me an error message (shown below)

    musictime = pygame.mixer.music.get_pos()
    pygame.mixer.music.stop()
    pygame.mixer.music.load("music3slow.ogg")
    pygame.mixer.music.set_pos(musictime * 2)
    pygame.mixer.music.play()

the error I got was this:

AttributeError: 'module' object has no attribute 'set_pos'

I don't know what I'm doing wrong, like I said it worked when I tried it before, it's probably something stupid but sometimes you just need the eyes of somebody else to see where you've messed up, thanks in advance :)

Это было полезно?

Решение

if set_pos() doesn't work try

pygame.mixer.music.play(0,(put what you need here)

I don't know why set_pos() sometimes doesn't work but the play option will and it does the same thing as set_pos

Другие советы

set_pos doesn't exist because it's a new method in 1.9.2. You have pygame version 1.9.1 according to your comments.

from https://www.pygame.org/docs/ref/music.html#pygame.mixer.music.set_pos

pygame.mixer.music.set_pos()

... description...

Function set_pos() calls underlining SDL_mixer function Mix_SetMusicPosition.

New in Pygame 1.9.2

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top