you defined a class and the things right in the class-definition are executed when (point in the code) the class is defined
so you should better do something like:
class Backgroundmusic:#load background music and play
def __init__(self)
self.music = base.loadMusic('sounds/The_Amulet.mp3')
self.music.setVolume(1) #Volume is a percentage from 0 to 1
self.music.setLoopCount(0) #0 means loop forever, 1 (default) means
self.music.play()
class Backgroundmusic:#load background music and play
def __init__(self):
self.music = base.loadMusic('sounds/The_Amulet.mp3')
self.music.setVolume(1) #Volume is a percentage from 0 to 1
self.music.setLoopCount(0) #0 means loop forever, 1 (default) means
self.music.play()
m=Backgroundmusic
Ok I switched to this and now no music will play- I looked up other examples and it appears correct, looked in my book and it appeared correct- so why doesn’t this make music when the:
class backgroundmusic(object):
without the
def_init_(self):
does play it.
I tested the code with my gui’s and it works right but why not the music?
The former is simply assigning m to the Backgroundmusic class object; it is not creating a new instance of Backgroundmusic, and never calling your init() method.
The latter is creating a new instance of Backgroundmusic, which calls your init() method.