Phaser API Documentation

  Version: 
batchDraw(entries, [x], [y], [alpha], [tint])

Description:

Use this method if you have already called beginDraw and need to batch draw a large number of objects to this Render Texture.

This method batches the drawing of the given objects to this texture, without causing a WebGL bind or batch flush for each one.

It is faster than calling draw, but you must be careful to manage the flow of code and remember to call endDraw(). 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 method can accept any of the following:

  • Any renderable Game Object, such as a Sprite, Text, Graphics or TileSprite.
  • Tilemap Layers.
  • A Group. The contents of which will be iterated and drawn in turn.
  • A Container. The contents of which will be iterated fully, and drawn in turn.
  • A Scene's Display List. Pass in Scene.children to draw the whole list.
  • Another Dynamic Texture or Render Texture.
  • A Texture Frame instance.
  • A string. This is used to look-up a texture from the Texture Manager.

Note: You cannot draw a Render Texture to itself.

If passing in a Group or Container it will only draw children that return true when their willRender() method is called. I.e. a Container with 10 children, 5 of which have visible=false will only draw the 5 visible ones.

If passing in an array of Game Objects it will draw them all, regardless if they pass a willRender check or not.

You can pass in a string in which case it will look for a texture in the Texture Manager matching that string, and draw the base frame. If you need to specify exactly which frame to draw then use the method drawFrame instead.

You can pass in the x and y coordinates to draw the objects at. The use of the coordinates differ based on what objects are being drawn. If the object is a Group, Container or Display List, the coordinates are added to the positions of the children. For all other types of object, the coordinates are exact.

The alpha and tint values are only used by Texture Frames. Game Objects use their own alpha and tint values when being drawn.

Parameters:

name type arguments Default description
entries any

Any renderable Game Object, or Group, Container, Display List, other Dynamic or Texture, Texture Frame or an array of any of these.

x number <optional> 0

The x position to draw the Frame at, or the offset applied to the object.

y number <optional> 0

The y position to draw the Frame at, or the offset applied to the object.

alpha number <optional> 1

The alpha value. Only used when drawing Texture Frames to this texture. Game Objects use their own alpha.

tint number <optional> 0xffffff

The tint color value. Only used when drawing Texture Frames to this texture. Game Objects use their own tint. WebGL only.

Returns:
Description:

This Render Texture instance.