Thanks, this answers my question!

On Jan 2, 9:12 am, Jonathan Hartley <[email protected]> wrote:
> On Jan 2, 5:10 pm, Jonathan Hartley <[email protected]> wrote:
>
>
>
>
>
> > On Jan 2, 4:58 pm, Jonathan Hartley <[email protected]> wrote:
>
> > > On Jan 2, 6:29 am, Dummey <[email protected]> wrote:
>
> > > > I am currently trying to create a character that can face left/right
> > > > and while facing in these directions walk/jump. A basic side scrolling
> > > > character.
>
> > > > Now my question is, how should I build my character class? My original
> > > > thought was to extend the sprite class and just alter the image that
> > > > is inside that sprite to the one that I need. While this seems to work
> > > > for still images, animations do not run. Is there a convention on how
> > > > I should be approaching this? An example would also be great, most of
> > > > the games that I have been studying only end up using rotate.
>
> > > Hey there, I don't know much about much, but for the record, you
> > > shouldn't need to extend the sprite class to change the image that is
> > > displayed. Just re-assign to the sprite.image attribute as and when
> > > you need a different image displayed. I use this for left/right facing
> > > images, but presumably you could entirely manage manual animation this
> > > way - but the logic is outside the (unmodified) Sprite class, in your
> > > own code.
>
> > Actually, come to think of it, I already do use this for manual sprite
> > animation. My code possibly isn't the best use of the pyglet API, but
> > for what it's 
> > worth:http://code.google.com/p/brokenspell/source/browse/trunk/gamelib/spri...
>
> > The shown SpriteItem class is an in-game entity which is rendered
> > using a pyglet Sprite. Concrete in-game items (eg. 'Bird', 'Feather',
> > etc) inherit from this.
>
> > The 'animate()' method assigns to sprite.image as described. Note
> > self.images is a class-level list of images, assigned on application
> > start-up, and
> > self.frame_idx is an attribute that each instance assigns to when they
> > want to display a particular frame of animation.
>
> > Note that animate() is a little contorted: It used to assign to
> > sprite.x, sprite.y, sprite.rotation, sprite.image, but I found each of
> > these invoked sprite._update_position(), which is a bunch of
> > recalculation logic. Hence for performance I now assign to sprite._x,
> > sprite._y, etc (note the underscores), and then call
> > sprite._update_position() myself manually. If this is a silly thing to
> > do, I'm all ears. I didn't measure the performance, it just looked
> > like a lot of lines, but doubtless isn't very expensive in practice.
>
> > Best regards.
>
> Actually, come to think of it, I *did* measure the performance, and it
> moved me from about 80fps to 90fps without vsync on my lappy, which
> seemed worth it for such a small, self-contained contortion.
-- 
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pyglet-users?hl=en.


Reply via email to