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.
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
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