i have implemented a simple 2d renderer which works but not with textures or dynamic objects.
First to say is that i have 4 classes
that i think are the most important ones. Renderer
, Scene
,Sprite
, SpriteBatch
.
To explain what i am doing i will write a simple example.
var renderer = new Renderer();
var scene = new Scene();
var sprite1 = new Sprite();
scene.add(sprite1);
function render(){
sprite1.x += 0.01;
renderer.render(scene);
}
render();
And what happens inside the scene is that new SpriteBatch
is created when first adding a Sprite
to the scene and all further Sprites
added to scene will be attached to the same SpriteBatch
until the SpriteBatch
is full.
So my Problem is that the vertices
,
new Float32Array([-0.5, -0.5, 0.5, -0.5, -0.5, 0.5, -0.5, 0.5, 0.5, -0.5, 0.5, 0.5]);
are calculated when calling scene.add(sprite1)
. Which makes it very different for me to animate since the large vertexbuffer
is inside the SpriteBatch
. So when calling sprite1.x+= 0.01
i want to update only these vertices
which belong to sprite1
. However i cant see how to connect Sprite
,Scene
and SpriteBatch
together to achieve a "dynamic" batching.
What are common techniques to achieve that or can you think of an method to achieve what i want?