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

Re: [pygame] Surface objects



On 14.07.2011 22:51, sam.hacking@xxxxxxxx wrote:
On Thu, 14 Jul 2011 19:05 +0200, "DR0ID" <dr0id@xxxxxxxxxx> wrote:
An old experiment of mine, it might give you a clue how you can do it (actually it replaces the pygame Surface object with the SurfaceObject class):

https://python-pyknic.googlecode.com/svn/branches/pyknic-2.0/experimental/surfaceobject.py
 
Right, you appear to be doing the much the same thing, using super() to create the surface object. What I want to know is, how can you get it to act like that if you already have a surface. So, instead of passing in the size:
s = SurfaceObject((400,300))
You would pass in an existing pygame.Surface object.
s = pygame.Surface((400,300))
so = SurfaceObject(s)
One way I've just thought of, maybe if I create a new surface (through __init__) the same size as the surface passed in, then just blit the passed in surface onto the newly created surface.


Hi again

Well, this

s = pygame.Surface((400,300))
so = SurfaceObject(s)

is just a matter how the contructor works. I would be similar to the internal class "Wrapper" of the SurfaceObject, which creates a new surface and blits the content on it.

If you read the SurfaceObject's code carefully, you will see that I actually replace pygame.Surface with the Surface Object. This means
anytime you call pygame.Surface(...) you'll get a SurfaceObject instead of a pygame.Surface. So you actually work with instances of SurfaceObject. And it works with all surface functions because it inherits from pygame.Surface.

But maybe, this is the wrong approach for your "Problem", as others said, knowing more what you want can get you better solutions.

At a second thought, what you describe is a "copy-constructor". Do you really need a copy constructor or could you just have a method that makes a copy of an existing SurfaceObject of yours?

~DR0ID