Hey George, On Sep 3, 1:59 am, George Oliver <[email protected]> wrote: > On Sep 2, 2:05 pm, Jonathan Hartley <[email protected]> wrote: > > > Hi all. > > > I have a bunch of game entities, which I'm drawing with pyglet > > sprites. I'm interested in batching them for performance. > > > My issue is that each of my in-game entities has about a half-dozen > > frames of animation (for actions like walking, and facing left, facing > > right.) So currently I create one sprite for each animation frame, and > > my game_ent.draw() method selects the correct sprite based on what the > > entity is currently up to (eg. walking left) and calls sprite.draw(). > > This works. > > Is there any reason to create separate sprites for what are just > different images? If you set the sprite.image to be whatever static > image or animation you like depending on the situation, batch.draw() > will take care of the rest. Or when you say sprites do you mean > images, and not pyglet.sprite.Sprites. > > For example, what I'm doing is loading all images and animations > (which are composed from sprite sheets) into an images class and an > animations class. The animations class creates a texture grid from the > sprite sheet and then the animation with a get_animation(), also > transforming it horizontally for the opposite direction. Anyway, then > when the sprite needs a different image I set the sprite.image to what > it needs, either an images.image or an animations.animation.
Thanks for this. With hindsight, no there is no reason to create a separate sprite for each image. I can see now that I should be reassigning the sprite.image attribute as you describe. Thanks for the hand-holding, it is much appreciated! Also, when entities are removed from my game world, I should be setting their sprite's batch attribute to None? And deleting the sprite? Or is messing with the batch like this costly? Should I just set the sprite.visible = False for the time being, and clean up the batch (or create a new one) between waves / levels? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
