Ideas about PyGdx
, a pythonic wrapper for LibGDX Java library using Jython.
Sprite batches in java are used like so:
SpriteBatch batch = new SpriteBatch(); //init'd in create()
//...
//in render()
batch.begin();
batch.draw(texture,x,y,width,height);
batch.end();
maybe this could be better implemented in python using a context manager:
//in __init__(self)
batch = SpriteBatch()
//...
// in render(self)
with drawing(batch):
batch.draw(texture,x,y,width,height)
the batch.begin()/end() will be handled autoamtically. The reason i chose not to use with SpriteBatch() as batch:
is because it is hazardous to use new
(A.K.A. constructing a new object) ever in a render loop. (Calling new
60 times a second will bring your monster computer to a halt.)
We can probably just call begin on the given parameter during enter and end on exit, so it'll be good.
heres a simple implementation of this idea:
from contextlib import contextmanager
@contextmanager
def drawing(batch):
batch.begin()
yield
batch.end()
This will reduce boilerplate and greatly increase readability.
//more ideas to come...