Hi,

Your idea of an Animator is interesting. It would essentially replace what 
> the existing Sprite._animate method does. Slightly tweaking the 
> pyglet.resource caching would prevent wasted Textures, but the animation 
> frame updates need to happen somewhere. This might be a good solution. 
> However, the issue of frame update scheduling needs to happen somewhere. If 
> it's happening inside an Animator class, then the Sprite needs to be 
> informed of the update so that it can update it's texture/tex_coords.
>

Trying to clarify the Animator class. This is to be considered if indeed 
event dispatching has a negligible cost in terms of performance. So before 
discussing anything else, this needs to be confirmed. From what you wrote, 
this seems to be the case. :)

The Animator class is an EventDispatcher in the same way as you proposed 
the Animation to be an EventDispatcher. So it would dispatch events like 
"next_frame" and "on_animation_end". The Sprite(s) would register to their 
Animator's events in order to update its (their) texture and re-dispatch 
the event as you described. It's the Animator which schedule its animate method 
based on the duration of the frame.

Can't really make an UML diagram, so trying to show in a nutshell who's 
responsible of what:
class Animation:  <- This remains as the current implementation
- List of Images

class Animator(EventDispatcher):
- instance of an Animation object
- frame_index
- play() -> schedule a call to its _animate method
- pause() -> unschedule its _animate method
- _animate() -> increase frame_index by 1 (modulo total number of frames) 
and dispatch next_frame event.
- Maybe expose directly its Animation list of Images.

class Sprite(EventDipatcher):
- Receives an instance of an Image, Animation or Animator. If an Animation 
is received, creates a new Animator and give it the Animation instance. 
Call its start() method and delegate the logic of animation for this 
animator.

I hope this clarifies what I had in mind.

Cheers,
Daniel

-- 
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.

Reply via email to