I have a class for making sprites flyweight and I am using a decorator to call this class. Here is some code:
class flyweight:
def __init__(self, cls):
self._cls = cls
self.__instances = dict()
def __call__(self, title):
return self.__instances.setdefault((title), self._cls(title))
In this question I'll just simplify the code to show what is relevant.
@flyweight
class Sprite:
def __init__(self, title, surf=None):
self.title = title
self.surf = surf if surf is not None else pygame.image.load('Images/Sprites/'+title+'.png').convert_alpha()
self.w, self.h = self.surf.get_size()
@staticmethod
def from_colour(colour, size=(40,40)):
surf = pygame.Surface(size).convert(); surf.fill(colour)
return Sprite(colour, surf)
red = Sprite.from_colour((125,0,0))
But this gives me the error:
AttributeError: 'flyweight' object has no attribute 'from_colour'
Should I remodel my flyweight implementation or is there some way around this?