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

Re: [pygame] Classless Utilities?



Kris Schnee wrote:
I was just thinking of revising my music/sound functions, which are thin wrappers for Pygame's. One thing that struck me: I'd put most of the code into a JukeBox class, so that to play a sound you'd have to create an instance of it and pass a reference to it to any other object that needed to be able to play sounds. The point of making the class was to centralize the jukebox's data, eg. the set of loaded sounds. Otherwise I'd have bunch of functions and variables lying around in the music file, not linked to a particular object. It seems like the right thing to do, for the sake of having any part of my program able to play sound effects, but kind of inelegant. Thoughts?

Kris



Well, I did that with my loadsprite class, and ended up regretting it. Now I am forced to create dummy objects when I don't really need them, just to load the picture from the file. I wish I had left well enough alone and left it all as loose functions in the module.


I'll probably get around to changing it back, but what I really wish, is that Python modules WERE classes. That's all I wanted, really - a singleton that handled my data. The easiest way to get that in Python is to create a module.

--Kamilche