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

[pygame] pass by reference



Hey everybody,

I am trying to optimise on loading images and I was wondering if
images as passed by reference or if a new copy is made.

I want to load one image and use that as the image many instances of a class.

Right now, my code looks like this:

def __init__(self):
  self.image, self.rect = loadimage.load_image("enemy.png", -1)

This obviously loads the image for every instance of the class.

I was reading this webpage:
http://www.learningpython.com/2006/03/19/creating-a-game-in-python-using-pygame-part-two-creating-a-level/
and the code in there loads all the images in a function and passes it
off to each class.

I just wanted to know if it passed by reference or not, if not there
would be no point in changing the code since there is no real
advantage to doing it the other way.

Also I had a question about pygame.display.update(), Do I pass it the
rectangles that I want to update? Can I give it a list of rectangles?

Thanks for all your help and patience,
spot.