Python Forum
[PyGame] Music starts too early in state machine
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] Music starts too early in state machine
#1
Hello,

Been working on a game using the template in the state machine tutorial, but I've run into a little problem with loading and running music.

Creating-a-state-machine


The problem is that when load the music in Game.load_data() but it starts playing the instant the program opens, not when I enter the Game state, which I would prefer. I'd like to put different music for the Game and Menu states.

class Control:
    def __init__(self):
        pg.mixer.pre_init(44100, -16, 1, 2048)
        pg.mixer.init()
        pg.init()

class Game(States):
    def __init__(self):
        States.__init__(self)
        self.next = 'menu'
        self.block_size = 50
        self.load_data()
        self.new()

    def load_data(self):
        pg.mixer.music.load(path.join(snd_dir, "spacelifeNo14.ogg"))
        pg.mixer.music.play(loops=-1)


This is every reference I have to music in there. Maybe my mixer.init() is in the wrong spot, but I wanted it there so it works for the Game and the Menu
Reply


Messages In This Thread
Music starts too early in state machine - by michael1789 - Feb-27-2020, 03:57 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyGame] Creating multiple instances in State Machine. michael1789 0 1,794 Dec-21-2019, 12:50 AM
Last Post: michael1789

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020