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

[pygame] Python property conventions in my new Sprite class



Hi guys,

I would like to have your opinion on some decisions I made when writing a new Sprite class, as part of my Summer of Code project [1].
As part of this work. I wrote several new features related to the core Sprite class, which can be set and manipulated through new attributes of the class.
You can read about the new attributes and my implementation on my blog [2].

I've decided to make use of Python's properties feature [3] to have more control on these attributes, and apply some calculations in their getters and setters.

It would be awesome if any of you share your opinion on this approach of using methods instead of directly accessing class attributes.
I couldn't find any benchmarking data online and figured I'd write a profiling suite eventually.

This is the sprite code as of now:
https://github.com/n0nick/pygame-sprites/blob/master/sprite.py

There's still some work to be done there, namely caching (memoizing) the getters' value to avoid unnecessary calculations between frames.

Thanks in advance,

[1]Âhttp://www.google-melange.com/gsoc/proposal/review/google/gsoc2012/n0nick/28002
[2]Âhttp://dotfile.n0nick.net/its-midterms-time-already
[3]Âhttp://docs.python.org/library/functions.html#property

--
Your friend in time,
Sagie Maoz
sagie@xxxxxxxxxÂ// +1 (347) 556.5044 // +972 (52) 834-3339
http://sagie.maoz.info/Âhttp://n0nick.net/

/* simba says roar! */