new Debug(game)
A collection of methods for displaying debug information about game objects.
If your game is running in Canvas mode, then you should invoke all of the Debug methods from
your game's render function. This is because they are drawn directly onto the game canvas
itself, so if you call any debug methods outside of render they are likely to be overwritten
by the game itself.
If your game is running in WebGL then Debug will create a Sprite that is placed at the top of the Stage display list and bind a canvas texture to it, which must be uploaded every frame. Be advised: this is very expensive, especially in browsers like Firefox. So please only enable Debug in WebGL mode if you really need it (or your desktop can cope with it well) and disable it for production!
You can disable the debug module by omitting it from a custom build or by creating a Phaser Game with { enableDebug: false }.
When Phaser is built without the debug module, the debug methods are replaced with empty functions, so you can leave any debug calls in your code and they will be ignored.
But if you create a Phaser Game with { enableDebug: false }, it will have no debug module at all and attempting to access it will error.
Either remove the debug calls from your code or check for the existence of game.debug first.
Parameters:
| Name | Type | Description |
|---|---|---|
game |
Phaser.Game | A reference to the currently running game. |
- Source:
- src/utils/Debug.js line 30
Members
-
bmd : Phaser.BitmapData
-
In WebGL mode this BitmapData contains a copy of the debug canvas.
Type:
- Source:
- src/utils/Debug.js line 45
-
canvas : HTMLCanvasElement
-
The canvas to which Debug calls draws.
Type:
- HTMLCanvasElement
- Source:
- src/utils/Debug.js line 50
-
columnWidth : number
-
The spacing between columns.
Type:
- number
- Default Value:
-
- 100
- Source:
- src/utils/Debug.js line 67
-
context : CanvasRenderingContext2D
-
The 2d context of the canvas.
Type:
- CanvasRenderingContext2D
- Source:
- src/utils/Debug.js line 55
-
currentAlpha : number
-
The alpha of the Debug context, set before all debug information is rendered to it.
Type:
- number
- Default Value:
-
- 1
- Source:
- src/utils/Debug.js line 110
-
<protected> currentColor : string
-
Type:
- string
- Source:
- src/utils/Debug.js line 92
-
currentX : number
-
The current X position the debug information will be rendered at.
Type:
- number
- Source:
- src/utils/Debug.js line 98
-
currentY : number
-
The current Y position the debug information will be rendered at.
Type:
- number
- Source:
- src/utils/Debug.js line 104
-
dirty : boolean
-
Does the canvas need re-rendering?
Type:
- boolean
- Source:
- src/utils/Debug.js line 116
-
font : string
-
The font that the debug information is rendered in.
Type:
- string
- Default Value:
-
- 14px monospace
- Source:
- src/utils/Debug.js line 61
-
game : Phaser.Game
-
A reference to the currently running Game.
Type:
- Source:
- src/utils/Debug.js line 35
-
<readonly> isDisabled : boolean
-
If
enableDebug: falseis passed to Phaser.Game or if Phaser is built without the Debug class, this will be true.Type:
- boolean
- Source:
- src/utils/Debug.js line 123
-
lineHeight : number
-
The line height between the debug text.
Type:
- number
- Default Value:
-
- 16
- Source:
- src/utils/Debug.js line 73
-
lineWidth : number
-
The width of the stroke on lines and shapes. A positive number.
Type:
- number
- Default Value:
-
- 1
- Source:
- src/utils/Debug.js line 79
-
renderShadow : boolean
-
Should the text be rendered with a slight shadow? Makes it easier to read on different types of background.
Type:
- boolean
- Default Value:
-
- true
- Source:
- src/utils/Debug.js line 85
-
sprite : Phaser.Image
-
If debugging in WebGL mode, this is the Image displaying the debug BitmapData.
Type:
- Source:
- src/utils/Debug.js line 40
-
<static, constant> GEOM_AUTO : integer
-
Type:
- integer
- Source:
- src/utils/Debug.js line 142
-
<static, constant> GEOM_CIRCLE : integer
-
Type:
- integer
- Source:
- src/utils/Debug.js line 154
-
<static, constant> GEOM_ELLIPSE : integer
-
Type:
- integer
- Source:
- src/utils/Debug.js line 172
-
<static, constant> GEOM_LINE : integer
-
Type:
- integer
- Source:
- src/utils/Debug.js line 166
-
<static, constant> GEOM_POINT : integer
-
Type:
- integer
- Source:
- src/utils/Debug.js line 160
-
<static, constant> GEOM_RECTANGLE : integer
-
Type:
- integer
- Source:
- src/utils/Debug.js line 148
Methods
-
body(sprite [, color] [, filled])
-
Render a Sprites Physics body if it has one set. The body is rendered as a filled or stroked rectangle. This only works for Arcade Physics, Ninja Physics (AABB and Circle only) and Box2D Physics bodies. To display a P2 Physics body you should enable debug mode on the body when creating it.
Parameters:
Name Type Argument Default Description spritePhaser.Sprite The Sprite who's body will be rendered.
colorstring <optional>
'rgba(0,255,0,0.4)' Color of the debug rectangle to be rendered. The format is a CSS color string such as '#ff0000' or 'rgba(255,0,0,0.5)'.
filledboolean <optional>
true Render the body as a filled rectangle (true) or a stroked rectangle (false)
- Source:
- src/utils/Debug.js line 1107
-
bodyInfo(sprite, x, y [, color])
-
Render a Sprites Physic Body information.
Parameters:
Name Type Argument Default Description spritePhaser.Sprite The sprite to be rendered.
xnumber X position of the debug info to be rendered.
ynumber Y position of the debug info to be rendered.
colorstring <optional>
'rgb(255,255,255)' color of the debug info to be rendered. (format is css color string).
- Source:
- src/utils/Debug.js line 1140
-
<protected> boot()
-
Internal method that boots the debug displayer.
- Source:
- src/utils/Debug.js line 176
-
box2dBody(body [, color])
-
Renders 'debug draw' data for the given Box2D body. This uses the standard debug drawing feature of Box2D, so colors will be decided by the Box2D engine.
Parameters:
Name Type Argument Default Description bodyPhaser.Physics.Box2D.Body The body to be rendered.
colorstring <optional>
'rgb(0,255,0)' Color of the rendering (format is css color string).
- Source:
- src/utils/Debug.js line 1185
-
box2dWorld()
-
Renders 'debug draw' data for the Box2D world if it exists. This uses the standard debug drawing feature of Box2D, so colors will be decided by the Box2D engine.
- Source:
- src/utils/Debug.js line 1168
-
camera(camera [, color] [, filled])
-
Marks the follow target and deadzone.
Parameters:
Name Type Argument Default Description cameraPhaser.Camera The Phaser.Camera to show the debug information for.
colorstring <optional>
Color of the debug shapes to be rendered (format is css color string).
filledboolean <optional>
true Render the shapes filled (default, true) or stroked (false).
- Source:
- src/utils/Debug.js line 464
-
cameraInfo(camera, x, y [, color])
-
Render camera information including dimensions and location.
Parameters:
Name Type Argument Default Description cameraPhaser.Camera The Phaser.Camera to show the debug information for.
xnumber X position of the debug info to be rendered.
ynumber Y position of the debug info to be rendered.
colorstring <optional>
'rgb(255,255,255)' color of the debug info to be rendered. (format is css color string).
- Source:
- src/utils/Debug.js line 492
-
destroy()
-
Destroy this object.
- Source:
- src/utils/Debug.js line 1421
-
device(x, y [, color])
-
Shows device capabilities: Pointer Events, Touch Events, Web Audio, WebGL.
Parameters:
Name Type Argument Description xnumber ynumber colorstring <optional>
- Source:
- src/utils/Debug.js line 1398
-
displayList( [displayObject])
-
Call this function from the Dev Tools console.
It will scan the display list and output all of the Objects it finds, and their renderOrderIDs.
Note Requires a browser that supports console.group and console.groupEnd (such as Chrome)
Parameters:
Name Type Argument Description displayObjectObject <optional>
The displayObject level display object to start from. Defaults to the World.
- Source:
- src/utils/Debug.js line 1200
-
gameInfo(x, y [, color])
-
Render game info (ID, renderer, paused, stepping).
Parameters:
Name Type Argument Default Description xnumber X position of the debug info to be rendered.
ynumber Y position of the debug info to be rendered.
colorstring <optional>
'rgb(255,255,255)' color of the debug info to be rendered. (format is css color string).
- Source:
- src/utils/Debug.js line 326
-
geom(object [, color] [, filled] [, forceType])
-
Renders a Phaser geometry object including Rectangle, Circle, Ellipse, Point or Line.
Parameters:
Name Type Argument Default Description objectPhaser.Rectangle | Phaser.Circle | Phaser.Ellipse | Phaser.Point | Phaser.Line The geometry object to render.
colorstring <optional>
Color of the debug info to be rendered (format is css color string).
filledboolean <optional>
true Render the objected as a filled (default, true) or a stroked (false)
forceTypenumber <optional>
Phaser.Utils.Debug.GEOM_AUTO Force rendering of a specific type: (0) GEOM_AUTO, 1 GEOM_RECTANGLE, (2) GEOM_CIRCLE, (3) GEOM_POINT, (4) GEOM_LINE, (5) GEOM_ELLIPSE.
- Source:
- src/utils/Debug.js line 926
-
inputHandler(handler, name, x, y, color)
-
Prints information about an input handler, e.g.
this.input.mouse.Parameters:
Name Type Description handlerPhaser.Keyboard | Phaser.Mouse | Phaser.MouseWheel | Phaser.MSPointer | Phaser.PointerLock namestring xnumber ynumber colorstring - Source:
- src/utils/Debug.js line 734
-
inputInfo(x, y [, color] [, showDetails])
-
Render debug information about the Input object.
Parameters:
Name Type Argument Default Description xnumber X position of the debug info to be rendered.
ynumber Y position of the debug info to be rendered.
colorstring <optional>
'rgb(255,255,255)' color of the debug info to be rendered. (format is css color string).
showDetailsboolean <optional>
true Also describe input sources and pointers.
- Source:
- src/utils/Debug.js line 672
-
key(key, x, y [, color])
-
Renders Phaser.Key object information.
Parameters:
Name Type Argument Default Description keyPhaser.Key The Key to render the information for.
xnumber X position of the debug info to be rendered.
ynumber Y position of the debug info to be rendered.
colorstring <optional>
'rgb(255,255,255)' color of the debug info to be rendered. (format is css color string).
- Source:
- src/utils/Debug.js line 652
-
<protected> line()
-
Internal method that outputs a single line of text split over as many columns as needed, one per parameter.
- Source:
- src/utils/Debug.js line 299
-
lineInfo(line, x, y [, color])
-
Renders Line information in the given color.
Parameters:
Name Type Argument Default Description linePhaser.Line The Line to display the data for.
xnumber X position of the debug info to be rendered.
ynumber Y position of the debug info to be rendered.
colorstring <optional>
'rgb(255,255,255)' color of the debug info to be rendered. (format is css color string).
- Source:
- src/utils/Debug.js line 889
-
loader(loader, x, y [, color])
-
Prints the progress of a Phaser.Loader.
Typically you would call this within a State#loadRender callback and pass
game.load(Phaser.Game#load).You can enable Phaser.Loader#resetLocked to temporarily hold the loader in its 'complete' state. Just remember to disable it before restarting the loader (such as when changing states).
Parameters:
Name Type Argument Default Description loaderPhaser.Loader The loader. Usually
game.load(Phaser.Game#load).xnumber The X value the debug info will start from.
ynumber The Y value the debug info will start from.
colorstring <optional>
'rgb(255,255,255)' The color the debug text will drawn in.
- Source:
- src/utils/Debug.js line 1353
-
phaser(x, y [, color])
-
Prints Phaser version, rendering mode, and device audio support.
Parameters:
Name Type Argument Default Description xnumber The X value the debug info will start from.
ynumber The Y value the debug info will start from.
colorstring <optional>
'rgb(255,255,255)' The color the debug text will drawn in.
- Source:
- src/utils/Debug.js line 1304
-
physicsGroup(group [, color] [, filled] [, checkExists])
-
Render each physics body in a group.
Parameters:
Name Type Argument Default Description groupPhaser.Group A group containing physics-enabled sprites.
colorstring <optional>
'rgba(0,255,0,0.4)' Color of the debug rectangle to be rendered. The format is a CSS color string such as '#ff0000' or 'rgba(255,0,0,0.5)'.
filledboolean <optional>
true Render the body as a filled rectangle (true) or a stroked rectangle (false).
checkExistsboolean <optional>
false Render only children with
exists=true.- Source:
- src/utils/Debug.js line 1290
-
pixel(x, y [, color] [, size])
-
Renders a single pixel at the given size.
Parameters:
Name Type Argument Default Description xnumber X position of the pixel to be rendered.
ynumber Y position of the pixel to be rendered.
colorstring <optional>
Color of the pixel (format is css color string).
sizenumber <optional>
2 The width and height of the rendered pixel.
- Source:
- src/utils/Debug.js line 907
-
pointer(pointer [, hideIfUp] [, downColor] [, upColor] [, color] [, inactiveColor])
-
Renders the Pointer.circle object onto the stage in green if down or yellow if up along with debug text.
Parameters:
Name Type Argument Default Description pointerPhaser.Pointer The Pointer you wish to display.
hideIfUpboolean <optional>
false Doesn't render the circle if the pointer is up.
downColorstring <optional>
'rgba(0,255,0,0.5)' The color the circle is rendered in if the Pointer is down.
upColorstring <optional>
'rgba(255,255,0,0.5)' The color the circle is rendered in if the Pointer is up (and hideIfUp is false).
colorstring <optional>
'rgb(255,255,255)' color of the debug info to be rendered. (format is css color string).
inactiveColorstring <optional>
'rgb(255,0,0,0.5)' The color the circle is rendered in if the Pointer is inactive.
- Source:
- src/utils/Debug.js line 539
-
<protected> preUpdate()
-
Internal method that clears the canvas (if a Sprite) ready for a new debug session.
- Source:
- src/utils/Debug.js line 220
-
quadTree(quadtree, color)
-
Visually renders a QuadTree to the display.
Parameters:
Name Type Description quadtreePhaser.QuadTree The quadtree to render.
colorstring The color of the lines in the quadtree.
- Source:
- src/utils/Debug.js line 1068
-
rectangle(object [, color] [, filled])
-
Renders a Rectangle.
Parameters:
Name Type Argument Default Description objectPhaser.Rectangle | object The rectangle to render.
colorstring <optional>
Color of the debug info to be rendered (format is css color string).
filledboolean <optional>
true Render the rectangle as filled (default, true) or a stroked (false)
- Source:
- src/utils/Debug.js line 1007
-
renderer( [x] [, y] [, color])
-
Prints a description of the renderer and render session.
Parameters:
Name Type Argument Default Description xnumber <optional>
0 The X value the debug info will start from.
ynumber <optional>
0 The Y value the debug info will start from.
colorstring <optional>
'rgb(255,255,255)' The color the debug text will drawn in.
- Source:
- src/utils/Debug.js line 1232
-
reset()
-
Clears the Debug canvas.
- Source:
- src/utils/Debug.js line 238
-
<protected> resize()
-
Internal method that resizes the BitmapData and Canvas. Called by ScaleManager.onSizeChange only in WebGL mode.
- Source:
- src/utils/Debug.js line 205
-
ropeSegments(rope [, color] [, filled])
-
Renders the Rope's segments. Note: This is really expensive as it has to calculate new segments every time you call it
Parameters:
Name Type Argument Default Description ropePhaser.Rope The rope to display the segments of.
colorstring <optional>
Color of the debug info to be rendered (format is css color string).
filledboolean <optional>
true Render the rectangle as a fillRect (default, true) or a strokeRect (false)
- Source:
- src/utils/Debug.js line 821
-
scale(x, y [, color])
-
Prints game/canvas dimensions and game scale settings.
Parameters:
Name Type Argument Default Description xnumber The X value the debug info will start from.
ynumber The Y value the debug info will start from.
colorstring <optional>
'rgb(255,255,255)' The color the debug text will drawn in.
- Source:
- src/utils/Debug.js line 1320
-
sound(x, y [, color])
-
Render Sound Manager information, including volume, mute, audio mode, and locked status.
Parameters:
Name Type Argument Default Description xnumber X position of the debug info to be rendered.
ynumber Y position of the debug info to be rendered.
colorstring <optional>
'rgb(255,255,255)' color of the debug info to be rendered. (format is css color string).
- Source:
- src/utils/Debug.js line 386
-
soundInfo(sound, x, y [, color])
-
Render Sound information, including decoded state, duration, volume and more.
Parameters:
Name Type Argument Default Description soundPhaser.Sound The sound object to debug.
xnumber X position of the debug info to be rendered.
ynumber Y position of the debug info to be rendered.
colorstring <optional>
'rgb(255,255,255)' color of the debug info to be rendered. (format is css color string).
- Source:
- src/utils/Debug.js line 416
-
spriteBounds(sprite [, color] [, filled])
-
Renders the Sprites bounds. Note: This is really expensive as it has to calculate the bounds every time you call it!
Parameters:
Name Type Argument Default Description spritePhaser.Sprite | Phaser.Image The sprite to display the bounds of.
colorstring <optional>
Color of the debug info to be rendered (format is css color string).
filledboolean <optional>
true Render the rectangle as a fillRect (default, true) or a strokeRect (false)
- Source:
- src/utils/Debug.js line 803
-
spriteCoords(sprite, x, y [, color])
-
Renders the sprite coordinates in local, positional and world space.
Parameters:
Name Type Argument Default Description spritePhaser.Sprite | Phaser.Image The sprite to display the coordinates for.
xnumber X position of the debug info to be rendered.
ynumber Y position of the debug info to be rendered.
colorstring <optional>
'rgb(255,255,255)' color of the debug info to be rendered. (format is css color string).
- Source:
- src/utils/Debug.js line 864
-
spriteInfo(sprite, x, y [, color])
-
Render debug infos (including name, bounds info, position and some other properties) about the Sprite.
Parameters:
Name Type Argument Default Description spritePhaser.Sprite The Sprite to display the information of.
xnumber X position of the debug info to be rendered.
ynumber Y position of the debug info to be rendered.
colorstring <optional>
'rgb(255,255,255)' color of the debug info to be rendered. (format is css color string).
- Source:
- src/utils/Debug.js line 841
-
spriteInputInfo(sprite, x, y [, color])
-
Render Sprite Input Debug information.
Parameters:
Name Type Argument Default Description spritePhaser.Sprite | Phaser.Image The sprite to display the input data for.
xnumber X position of the debug info to be rendered.
ynumber Y position of the debug info to be rendered.
colorstring <optional>
'rgb(255,255,255)' color of the debug info to be rendered. (format is css color string).
- Source:
- src/utils/Debug.js line 632
-
<protected> start( [x] [, y] [, color] [, columnWidth])
-
Internal method that resets and starts the debug output values.
Parameters:
Name Type Argument Default Description xnumber <optional>
0 The X value the debug info will start from.
ynumber <optional>
0 The Y value the debug info will start from.
colorstring <optional>
'rgb(255,255,255)' The color the debug text will drawn in.
columnWidthnumber <optional>
0 The spacing between columns.
- Source:
- src/utils/Debug.js line 256
-
state(x, y [, color])
-
Render game state info.
Icons show (+) pending, (>) loading, (*) created.
Parameters:
Name Type Argument Default Description xnumber X position of the debug info to be rendered.
ynumber Y position of the debug info to be rendered.
colorstring <optional>
'rgb(255,255,255)' color of the debug info to be rendered. (format is css color string).
- Source:
- src/utils/Debug.js line 348
-
<protected> stop()
-
Internal method that stops the debug output.
- Source:
- src/utils/Debug.js line 288
-
text(text, x, y [, color] [, font])
-
Render a string of text.
Parameters:
Name Type Argument Description textstring The line of text to draw.
xnumber X position of the debug info to be rendered.
ynumber Y position of the debug info to be rendered.
colorstring <optional>
Color of the debug info to be rendered (format is css color string).
fontstring <optional>
The font of text to draw.
- Source:
- src/utils/Debug.js line 1038
-
timer(timer, x, y [, color])
-
Render Timer information.
Parameters:
Name Type Argument Default Description timerPhaser.Timer The Phaser.Timer to show the debug information for.
xnumber X position of the debug info to be rendered.
ynumber Y position of the debug info to be rendered.
colorstring <optional>
'rgb(255,255,255)' color of the debug info to be rendered. (format is css color string).
- Source:
- src/utils/Debug.js line 521