I'm working on a game in pygame-ce
as a hobby, for scene management I've implemented a finite state machine. The problem is, it currently only kind of works, as the scene object is not garbage collected and then reinitialized
in between "state flips". Which results in attributes not being reset etc. The most elegant way to deal with this is (imo) to define the scene class as a singleton, except that it doesn't keep a new instance from being created and instead always replaces the previous instance.
The idea would be something along these lines, meant as pseudo code:
class MySpecialSingleton:
instance = [0]
def __init__(self):
instance[0] = MySpecialSingleton.__init__
So basically when MainMenu(MySpecialSingleton)
is created, Splashscreen(MySpecialSingleton)
is garbage collected.