I'm attempting to make use of the pyglet.graphics.Batch class to make
it less resource intensive to generate individual sprites. It was
working when I first had the implementation, however, I thought of
splitting it into its own module for added organization, as it will be
bigger. However, it seems that now a black screen generates in place
of sprites. I'm new to using Pyglet, so I'd also appreciate some hands-
on advice as well if my implementation could be better.
arena.py
---------------------------------------------
from pyglet import image
from pyglet.graphics import Batch
from pyglet.sprite import Sprite
class Arena():
def __init__(self):
self.panels = {}
def set_panels(self):
panel_red = image.load('panel_red.png')
panel_blue = image.load('panel_blue.png')
panel_batch = Batch()
panel = [Sprite(panel_red, x=0, y=87, batch=panel_batch),
Sprite(panel_red, x=40, y=87, batch=panel_batch),
Sprite(panel_red, x=80, y=87, batch=panel_batch),
Sprite(panel_red, x=0, y=87+24,
batch=panel_batch),
Sprite(panel_red, x=40, y=87+24,
batch=panel_batch),
Sprite(panel_red, x=80, y=87+24,
batch=panel_batch),
Sprite(panel_red, x=0, y=87+24+24,
batch=panel_batch),
Sprite(panel_red, x=40, y=87+24+24,
batch=panel_batch),
Sprite(panel_red, x=80, y=87+24+24,
batch=panel_batch),
Sprite(panel_blue, x=120, y=87,
batch=panel_batch),
Sprite(panel_blue, x=120+40, y=87,
batch=panel_batch),
Sprite(panel_blue, x=120+80, y=87,
batch=panel_batch),
Sprite(panel_blue, x=120, y=87+24,
batch=panel_batch),
Sprite(panel_blue, x=120+40, y=87+24,
batch=panel_batch),
Sprite(panel_blue, x=120+80, y=87+24,
batch=panel_batch),
Sprite(panel_blue, x=120, y=87+24+24,
batch=panel_batch),
Sprite(panel_blue, x=120+40, y=87+24+24,
batch=panel_batch),
Sprite(panel_blue, x=120+80, y=87+24+24,
batch=panel_batch)]
return panel_batch
arena = Arena()
---------------------------------------------
main.py
---------------------------------------------
from pyglet.app import run
from pyglet.window import Window
from arena import arena
window = Window(width = 252, height = 252, caption = 'MMBNOnline')
panels = arena.set_panels()
@window.event
def on_draw():
window.clear()
panels.draw()
run()
---------------------------------------------
Thank you for your time.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---