On 04/08/13 22:53, Fred wrote:
> [...]
>
> So my two questions :
> 1) Is this idea (modify texture rather than sprite) sufficient to
> improve performances ?
> 2) how to blit a texture on another ?
What about subclassing Sprite? I we had a similar thread no so long ago
but I couldn't find it in the archives :(
Something like the following (I wrote it on a rush, but it may work):
import pyglet
class AnimatedSprite(pyglet.sprite.Sprite):
def __init__(self, image, frames, delay=0.2, *args):
im = pyglet.resource.image(image)
self.images = [im.get_region(32*f, 0, 32, 32) for f in
range(frames)]
self.delay = delay
self.current_delay = 0
self.current_frame = 0
super(AnimatedSprite,
self).__init__(self.images[self.current_frame], *args)
def update(self, dt):
self.current_delay += dt
if self.current_delay > self.delay:
self.current_delay = 0
self.current_frame += 1
if self.current_frame >= len(self.images):
self.current_frame = 0
self.image = self.images[self.current_frame]
window = pyglet.window.Window()
anim = AnimatedSprite('anim.png', 3)
def update(dt):
anim.update(dt)
@window.event
def on_draw():
window.clear()
anim.draw()
pyglet.clock.schedule_interval(update, 1/60.0)
pyglet.app.run()
Note that resource will make a texture atlas bin. The code is assuming
the animation will be in a single image, with all frames horizontally, etc.
Also I usually add 1 pixel border to the frames to avoid pixel bleeding
because OpenGL etc.
Just include all the sprites in a batch and draw the batch and your
performance should be OK.
Regards,
Juan
--
jjm's home: http://www.usebox.net/jjm/
blackshell: http://blackshell.usebox.net/
--
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 http://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/groups/opt_out.