You can keep a list of the sprites for adding and removing them from 
batches:

import pyglet
from pyglet.gl import *

window = pyglet.window.Window(640,480)

rendered_sprites = []

batch = pyglet.graphics.Batch()

texture = pyglet.image.load('test.png').get_texture()

@window.event
def on_draw():
    window.clear()
    batch.draw()

@window.event
def on_key_press(symbol,modifiers):
    if symbol == pyglet.window.key.RETURN:
        rendered_sprites.append(batch.add(4, GL_QUADS, None,
                                          ('v2f/static', (0.0,0.0, 32.0,0.0, 
32.0,32.0, 0.0,32.0)),
                                          ('t3f/static', texture.tex_coords
)))

    if symbol == pyglet.window.key.SPACE:
        rendered_sprites.pop(0).delete()

pyglet.app.run()

You could also create two separate batches, one for active rendering and 
one for idle storage, then migrate selected sprites from one batch to 
another, though it may not be as efficient as other methods:

import pyglet
from pyglet.gl import *

window = pyglet.window.Window(640,480)

rendered_sprites = []

batch = pyglet.graphics.Batch()

batch_idle = pyglet.graphics.Batch()

texture = pyglet.image.load('test.png').get_texture()

rendered_sprites.append(batch.add(4, GL_QUADS, None,
                                  ('v2f/static', (0.0,0.0, 32.0,0.0, 32.0,
32.0, 0.0,32.0)),
                                  ('t3f/static', texture.tex_coords)))

@window.event
def on_draw():
    window.clear()
    batch.draw()

@window.event
def on_key_press(symbol,modifiers):
    if symbol == pyglet.window.key.RETURN:
        batch.migrate(rendered_sprites[0],pyglet.gl.GL_QUADS, None,
batch_idle)

    if symbol == pyglet.window.key.SPACE:
            batch_idle.migrate(rendered_sprites[0],pyglet.gl.GL_QUADS, None,
batch)

pyglet.app.run()



-- 
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 https://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.

Reply via email to