This method enables rendering of the Mesh vertices to the given Graphics instance.
If you enable this feature, you must call Graphics.clear()
in your Scene update
,
otherwise the Graphics instance you provide to debug will fill-up with draw calls,
eventually crashing the browser. This is not done automatically to allow you to debug
draw multiple Mesh objects to a single Graphics instance.
The Mesh class has a built-in debug rendering callback Mesh.renderDebug
, however
you can also provide your own callback to be used instead. Do this by setting the callback
parameter.
The callback is invoked once per render and sent the following parameters:
callback(src, faces)
src
is the Mesh instance being debugged.
faces
is an array of the Faces that were rendered.
You can get the final drawn vertex position from a Face object like this:
let face = faces[i];
let x0 = face.vertex1.tx;
let y0 = face.vertex1.ty;
let x1 = face.vertex2.tx;
let y1 = face.vertex2.ty;
let x2 = face.vertex3.tx;
let y2 = face.vertex3.ty;
graphic.strokeTriangle(x0, y0, x1, y1, x2, y2);
If using your own callback you do not have to provide a Graphics instance to this method.
To disable debug rendering, to either your own callback or the built-in one, call this method with no arguments.
name | type | arguments | description |
---|---|---|---|
graphic | Phaser.GameObjects.Graphics | <optional> |
The Graphic instance to render to if using the built-in callback. |
callback | function | <optional> |
The callback to invoke during debug render. Leave as undefined to use the built-in callback. |
This Game Object instance.