[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [pygame] gui module



Hi.

> This is GUI exactly what I've been looking for! I don't want the full
> functionality, but its very helpful to see some of the techniques used for
> building a GUI.

Cool, glad you find it helpful.
 
> A question: in the visual.py module, the Sprite class has a method 'update'
> defined as follows:
> 
> def update(self, time):
>     self.image = self.animation.next(time, self)
>     self.pos = self.mover.next(time)
> 
> Where do the self.animation.next and self.mover.next functions get defined?
> I don't understand why this doesn't produce a compile time error, since the
> Sprite class only inherits from pygame.sprite.Sprite. What have I missed?

It doesn't produce a compile time error because Python doesn't have compile
time errors :). The idea is that the 'animation' attribute is an instance of
the Animation class (or a class with the same methods), and the 'mover'
attribute is an instance of StraightMover (or a class with the same methods).
The Sprite class itself doesn't create these attributes, this is left up to
subclasses or whatever else to assign to them. See the test function
i_test_Sprite for a little example.

 The thing is though, the actual gui stuff
never calls Sprite.update because the Widget class, which is the subclass
of Sprite that all the widgets are derived from, overrides the update method
to do nothing. Some of the actual widgets override that method again because they
use it, but none of them use an animation or a mover attribute. I wrote the
Sprite class intending to use it for regular animation sprites too, not just
the GUI stuff, and I was planning on (and I will at some point) using the 
animation and mover attributes for that.

-- 
Mike Benfield
____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org