Wednesday, February 5, 2014

Python Inherit Pygame Surface

Learned new thing about python classes recently. In order to create a class that is a surface you have to initiate the surface. This is done by doing the following.

class MySurface(pygame.Surface):
    def __init__(self, width, height, image):
        pygame.Surface.__init__(self, width, height)
        self.blit(image, (0, 0, width, height))

2 comments:

  1. thanks for this post
    i really had hard time figuring out why my surface was remaining empty after leaving the init function

    ReplyDelete