Writing your own sprite class is fairly straight forward (I do it all the
time), though you should keep in mind
you may run into the same performance issues if you have a huge number of
sprites because your system
still has to iterate over each one of them to update them. In which case
you'll have to find other ways to boost
performance.
Anyway, here's a simple custom class example:
class my_sprite(object):
def __init__(self,x,y):
#load the sprites tileset into a texture grid
#(optionally pass a reference from the tileset to the sprite
#in the init function so you don't have keep loading it all the time)
self.image = pyglet.image.TextureGrid(pyglet.image.ImageGrid(pyglet.
image.load("tileset.png"),1,6))
#display how many images are in the animation
print len(self.image)
#x position of sprite
self.x = x
#y position of sprite
self.y = y
#current frame of sprite
self.frame = 0
#rate to update each frame
self.frame_rate = .5
#update the sprite
def update(self):
self.frame += self.frame_rate
#draw sprite (method may vary)
def draw(self):
self.image[int(self.frame)].blit(self.x,self.y)
class main_program_whatever(object):
def __init__(self):
self.sprite = my_sprite(16,16)
def update(self):
for a in self.sprite:
a.update()
--
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/d/optout.