[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Extending Surface Class



Hi

I would write a wrapper instead of inheriting from Surface because Surface is a C object.

class MySurface(object):
   def __init__(self):
       self._sruf = Surface()

I know, you would have to wrap all methods, but maybe this could be done using setattr.

~DR0ID

ERName schrieb:
Is it possible to extend the surface class? Every time I do the
surface ends up dieing somehow right after it is created... I may just
be doing it in the wrong way, though. The main point is to override
the __str__() method, so if you know another way besides extending
pygame.Surface, I'd be happy to hear it.


class ExtendedSurface(pygame.Surface):

    def __init__(self, surface, string):
        pygame.Surface.__init__(surface, surface.get_size()) #The docs
say to include a size, etc. but that just gives me "too many values to
unpack" errors.
        self.string = string

    def __str__(self):
        return self.string



Thanks!