Something along the lines of this I beleive:
class my_sprite(object):
def __init__(self,x,y,surface):
#store reference to batch surface so sprite can update it
self.surface = surface
#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,image):
self.frame += self.frame_rate
#if frame is greater than the number of images, reset it
if self.frame >= len(self.image):
self.frame = 0
#update the sprites image in the batch
self.surface.tex_coords = image[int(self.frame)].tex_coords
class main_program_whatever(object):
def __init__(self):
#load the sprites tileset into texture grid
self.image = pyglet.image.TextureGrid(pyglet.image.ImageGrid(pyglet.
image.load("tileset.png"),1,6))
#load batch
self.batch = pyglet.graphics.Batch()
#create a vertex list surface for sprite(s) to draw on
self.surface = (self.batch.add(4, pyglet.gl.GL_QUADS, group(1),
('v2f',((a*32),(b*32), 32+(a*32),(b*32), 32+(a*32),32+(b*32
), (a*32),32+(b*32))),
('t3f',(0,0,0, 0,0,0, 0,0,0, 0,0,0))))
#load sprite and pass a reference to the surface(s) to draw on
self.sprite = my_sprite(16,16,self.surface)
#update sprite
def update(self):
for a in self.sprite:
#pass reference to tileset so sprite can set tex_coords
a.update(self.image)
#draw batch
def draw(self):
self.batch.draw()
#handle the texture(s)/layer(s) during batch rendering
class group(pyglet.graphics.OrderedGroup):
def set_state(self):
#reference the time tileset in Window for batch rendering
if self.order == 1:
glBindTexture(GL_TEXTURE_2D, window.image.id)
--
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.