Use this method if you need to batch draw a large number of Game Objects to this Render Texture in a single pass, or on a frequent basis. This is especially useful under WebGL, however, if your game is using Canvas only, it will not make any speed difference in that situation.
This method starts the beginning of a batched draw, unless one is already open.
Batched drawing is faster than calling draw
in loop, but you must be careful
to manage the flow of code and remember to call endDraw()
when you're finished.
If you don't need to draw large numbers of objects it's much safer and easier
to use the draw
method instead.
The flow should be:
// Call once:
RenderTexture.beginDraw();
// repeat n times:
RenderTexture.batchDraw();
// or
RenderTexture.batchDrawFrame();
// Call once:
RenderTexture.endDraw();
Do not call any methods other than batchDraw
, batchDrawFrame
, or endDraw
once you
have started a batch. Also, be very careful not to destroy this Render Texture while the
batch is still open. Doing so will cause a run-time error in the WebGL Renderer.
You can use the RenderTexture.texture.isDrawing
boolean property to tell if a batch is
currently open, or not.
This Render Texture instance.