Skip to main content
Version: Phaser v4.0.0-rc.6

Graphics

A Graphics object is a way to draw primitive shapes to your game. Primitives include forms of geometry, such as

Rectangles, Circles, and Polygons. They also include lines, arcs and curves. When you initially create a Graphics

object it will be empty.

To draw to it you must first specify a line style or fill style (or both), draw shapes using paths, and finally

fill or stroke them. For example:


graphics.lineStyle(5, 0xFF00FF, 1.0);

graphics.beginPath();

graphics.moveTo(100, 100);

graphics.lineTo(200, 200);

graphics.closePath();

graphics.strokePath();

There are also many helpful methods that draw and fill/stroke common shapes for you.


graphics.lineStyle(5, 0xFF00FF, 1.0);

graphics.fillStyle(0xFFFFFF, 1.0);

graphics.fillRect(50, 50, 400, 200);

graphics.strokeRect(50, 50, 400, 200);

When a Graphics object is rendered it will render differently based on if the game is running under Canvas or WebGL.

Under Canvas it will use the HTML Canvas context drawing operations to draw the path.

Under WebGL the graphics data is decomposed into polygons. Both of these are expensive processes, especially with

complex shapes.

If your Graphics object doesn't change much (or at all) once you've drawn your shape to it, then you will help

performance by calling Phaser.GameObjects.Graphics#generateTexture. This will 'bake' the Graphics object into

a Texture, and return it. You can then use this Texture for Sprites or other display objects. If your Graphics object

updates frequently then you should avoid doing this, as it will constantly generate new textures, which will consume

memory.

Under WebGL, Graphics uses its own shader which will batch drawing operations.

Try to keep Graphics objects grouped together so they can be batched together.

Avoid mixing object types where possible, as each batch will be flushed,

costing performance.

As you can tell, Graphics objects are a bit of a trade-off. While they are extremely useful, you need to be careful

in their complexity and quantity of them in your game.

Constructor

new Graphics(scene, [options])

Parameters

nametypeoptionaldescription
scenePhaser.SceneNoThe Scene to which this Graphics object belongs.
optionsPhaser.Types.GameObjects.Graphics.OptionsYesOptions that set the position and default style of this Graphics object.

Scope: static

Extends

Phaser.GameObjects.GameObject
Phaser.GameObjects.Components.AlphaSingle
Phaser.GameObjects.Components.BlendMode
Phaser.GameObjects.Components.Depth
Phaser.GameObjects.Components.Lighting
Phaser.GameObjects.Components.Mask
Phaser.GameObjects.Components.RenderNodes
Phaser.GameObjects.Components.Transform
Phaser.GameObjects.Components.Visible
Phaser.GameObjects.Components.ScrollFactor

Source: src/gameobjects/graphics/Graphics.js#L19
Since: 3.0.0

Inherited Members

From Phaser.GameObjects.Components.AlphaSingle:

From Phaser.GameObjects.Components.BlendMode:

From Phaser.GameObjects.Components.Depth:

From Phaser.GameObjects.Components.Filters:

From Phaser.GameObjects.Components.Lighting:

From Phaser.GameObjects.Components.Mask:

From Phaser.GameObjects.Components.RenderNodes:

From Phaser.GameObjects.Components.ScrollFactor:

From Phaser.GameObjects.Components.Transform:

From Phaser.GameObjects.Components.Visible:

From Phaser.GameObjects.GameObject:


Public Members

commandBuffer

commandBuffer: array

Description:

The array of commands used to render the Graphics.

Source: src/gameobjects/graphics/Graphics.js#L133
Since: 3.0.0


defaultFillAlpha

defaultFillAlpha: number

Description:

The default fill alpha for shapes rendered by this Graphics object.

Set this value with setDefaultStyles().

Source: src/gameobjects/graphics/Graphics.js#L155
Since: 3.0.0


defaultFillColor

defaultFillColor: number

Description:

The default fill color for shapes rendered by this Graphics object.

Set this value with setDefaultStyles().

Source: src/gameobjects/graphics/Graphics.js#L143
Since: 3.0.0


defaultStrokeAlpha

defaultStrokeAlpha: number

Description:

The default stroke alpha for shapes rendered by this Graphics object.

Set this value with setDefaultStyles().

Source: src/gameobjects/graphics/Graphics.js#L191
Since: 3.0.0


defaultStrokeColor

defaultStrokeColor: number

Description:

The default stroke color for shapes rendered by this Graphics object.

Set this value with setDefaultStyles().

Source: src/gameobjects/graphics/Graphics.js#L179
Since: 3.0.0


defaultStrokeWidth

defaultStrokeWidth: number

Description:

The default stroke width for shapes rendered by this Graphics object.

Set this value with setDefaultStyles().

Source: src/gameobjects/graphics/Graphics.js#L167
Since: 3.0.0


displayOriginX

displayOriginX: number

Description:

The horizontal display origin of the Graphics.

Source: src/gameobjects/graphics/Graphics.js#L113
Since: 3.0.0


displayOriginY

displayOriginY: number

Description:

The vertical display origin of the Graphics.

Source: src/gameobjects/graphics/Graphics.js#L123
Since: 3.0.0


pathDetailThreshold

pathDetailThreshold: number

Description:

Path detail threshold for the WebGL renderer, in pixels.

Path segments will be combined until the path is complete

or the segment length is above the threshold.

If the value is negative, the threshold will be taken from the

game config render.pathDetailThreshold property.

This threshold can greatly improve performance on complex shapes.

It is calculated at render time and does not affect the original

path data.

The threshold is evaluated in screen pixels, so if the object is

scaled up, fine detail will emerge.

Source: src/gameobjects/graphics/Graphics.js#L213
Since: 4.0.0


TargetCamera

TargetCamera: Phaser.Cameras.Scene2D.Camera

Description:

A Camera used specifically by the Graphics system for rendering to textures.

Source: src/gameobjects/graphics/Graphics.js#L1608
Since: 3.1.0


Inherited Methods

From Phaser.Events.EventEmitter:

From Phaser.GameObjects.Components.AlphaSingle:

From Phaser.GameObjects.Components.BlendMode:

From Phaser.GameObjects.Components.Depth:

From Phaser.GameObjects.Components.Filters:

From Phaser.GameObjects.Components.Lighting:

From Phaser.GameObjects.Components.Mask:

From Phaser.GameObjects.Components.RenderNodes:

From Phaser.GameObjects.Components.RenderSteps:

From Phaser.GameObjects.Components.ScrollFactor:

From Phaser.GameObjects.Components.Transform:

From Phaser.GameObjects.Components.Visible:

From Phaser.GameObjects.GameObject:


Public Methods

arc

<instance> arc(x, y, radius, startAngle, endAngle, [anticlockwise], [overshoot])

Description:

Draw an arc.

This method can be used to create circles, or parts of circles.

Make sure you call beginPath before starting the arc unless you wish for the arc to automatically

close when filled or stroked.

Use the optional overshoot argument increase the number of iterations that take place when

the arc is rendered in WebGL. This is useful if you're drawing an arc with an especially thick line,

as it will allow the arc to fully join-up. Try small values at first, i.e. 0.01.

Call Phaser.GameObjects.Graphics#fillPath or Phaser.GameObjects.Graphics#strokePath after calling

this method to draw the arc.

Parameters:

nametypeoptionaldefaultdescription
xnumberNoThe x coordinate of the center of the circle.
ynumberNoThe y coordinate of the center of the circle.
radiusnumberNoThe radius of the circle.
startAnglenumberNoThe starting angle, in radians.
endAnglenumberNoThe ending angle, in radians.
anticlockwisebooleanYesfalseWhether the drawing should be anticlockwise or clockwise.
overshootnumberYes0This value allows you to increase the segment iterations in WebGL rendering. Useful if the arc has a thick stroke and needs to overshoot to join-up cleanly. Use small numbers such as 0.01 to start with and increase as needed.

Returns: Phaser.GameObjects.Graphics - This Game Object.

Source: src/gameobjects/graphics/Graphics.js#L1285
Since: 3.0.0


beginPath

<instance> beginPath()

Description:

Start a new shape path.

Returns: Phaser.GameObjects.Graphics - This Game Object.

Source: src/gameobjects/graphics/Graphics.js#L422
Since: 3.0.0


clear

<instance> clear()

Description:

Clear the command buffer and reset the fill style and line style to their defaults.

Returns: Phaser.GameObjects.Graphics - This Game Object.

Source: src/gameobjects/graphics/Graphics.js#L1485
Since: 3.0.0


closePath

<instance> closePath()

Description:

Close the current path.

Returns: Phaser.GameObjects.Graphics - This Game Object.

Source: src/gameobjects/graphics/Graphics.js#L439
Since: 3.0.0


fill

<instance> fill()

Description:

Fill the current path.

This is an alias for Graphics.fillPath and does the same thing.

It was added to match the CanvasRenderingContext 2D API.

Returns: Phaser.GameObjects.Graphics - This Game Object.

Source: src/gameobjects/graphics/Graphics.js#L473
Since: 3.16.0


fillCircle

<instance> fillCircle(x, y, radius)

Description:

Fill a circle with the given position and radius.

Parameters:

nametypeoptionaldescription
xnumberNoThe x coordinate of the center of the circle.
ynumberNoThe y coordinate of the center of the circle.
radiusnumberNoThe radius of the circle.

Returns: Phaser.GameObjects.Graphics - This Game Object.

Source: src/gameobjects/graphics/Graphics.js#L560
Since: 3.0.0


fillCircleShape

<instance> fillCircleShape(circle)

Description:

Fill the given circle.

Parameters:

nametypeoptionaldescription
circlePhaser.Geom.CircleNoThe circle to fill.

Returns: Phaser.GameObjects.Graphics - This Game Object.

Source: src/gameobjects/graphics/Graphics.js#L530
Since: 3.0.0


fillEllipse

<instance> fillEllipse(x, y, width, height, [smoothness])

Description:

Fill an ellipse with the given position and size.

Parameters:

nametypeoptionaldefaultdescription
xnumberNoThe x coordinate of the center of the ellipse.
ynumberNoThe y coordinate of the center of the ellipse.
widthnumberNoThe width of the ellipse.
heightnumberNoThe height of the ellipse.
smoothnessnumberYes32The number of points to draw the ellipse with.

Returns: Phaser.GameObjects.Graphics - This Game Object.

Source: src/gameobjects/graphics/Graphics.js#L1260
Since: 3.0.0


fillEllipseShape

<instance> fillEllipseShape(ellipse, [smoothness])

Description:

Fill the given ellipse.

Parameters:

nametypeoptionaldefaultdescription
ellipsePhaser.Geom.EllipseNoThe ellipse to fill.
smoothnessnumberYes32The number of points to draw the ellipse with.

Returns: Phaser.GameObjects.Graphics - This Game Object.

Source: src/gameobjects/graphics/Graphics.js#L1240
Since: 3.0.0


fillGradientStyle

<instance> fillGradientStyle(topLeft, topRight, bottomLeft, bottomRight, [alphaTopLeft], [alphaTopRight], [alphaBottomLeft], [alphaBottomRight])

Description:

Sets a gradient fill style. This is a WebGL only feature.

The gradient color values represent the 4 corners of an untransformed rectangle.

The gradient is used to color all filled shapes and paths drawn after calling this method.

If you wish to turn a gradient off, call fillStyle and provide a new single fill color.

When filling a triangle only the first 3 color values provided are used for the 3 points of a triangle.

This feature is best used only on rectangles and triangles. All other shapes will give strange results.

Note that for objects such as arcs or ellipses, or anything which is made out of triangles, each triangle used

will be filled with a gradient on its own. There is no ability to gradient fill a shape or path as a single

entity at this time.

Tags:

  • webglOnly

Parameters:

nametypeoptionaldefaultdescription
topLeftnumberNoThe top left fill color.
topRightnumberNoThe top right fill color.
bottomLeftnumberNoThe bottom left fill color.
bottomRightnumberNoThe bottom right fill color. Not used when filling triangles.
alphaTopLeftnumberYes1The top left alpha value. If you give only this value, it's used for all corners.
alphaTopRightnumberYes1The top right alpha value.
alphaBottomLeftnumberYes1The bottom left alpha value.
alphaBottomRightnumberYes1The bottom right alpha value.

Returns: Phaser.GameObjects.Graphics - This Game Object.

Source: src/gameobjects/graphics/Graphics.js#L338
Since: 3.12.0


fillPath

<instance> fillPath()

Description:

Fill the current path.

Returns: Phaser.GameObjects.Graphics - This Game Object.

Source: src/gameobjects/graphics/Graphics.js#L456
Since: 3.0.0


fillPoint

<instance> fillPoint(x, y, [size])

Description:

Fill a point at the given position.

Draws a square at the given position, 1 pixel in size by default.

Parameters:

nametypeoptionaldefaultdescription
xnumberNoThe x coordinate of the point.
ynumberNoThe y coordinate of the point.
sizenumberYes1The size of the square to draw.

Returns: Phaser.GameObjects.Graphics - This Game Object.

Source: src/gameobjects/graphics/Graphics.js#L905
Since: 3.0.0


fillPoints

<instance> fillPoints(points, [closeShape], [closePath], [endIndex])

Description:

Fill the shape represented by the given array of points.

Pass closeShape to automatically close the shape by joining the last to the first point.

Pass closePath to automatically close the path before it is filled.

Parameters:

nametypeoptionaldefaultdescription
pointsArray.<Phaser.Math.Vector2>NoThe points to fill.
closeShapebooleanYesfalseWhen true, the shape is closed by joining the last point to the first point.
closePathbooleanYesfalseWhen true, the path is closed before being stroked.
endIndexnumberYesThe index of points to stop at. Defaults to points.length.

Returns: Phaser.GameObjects.Graphics - This Game Object.

Source: src/gameobjects/graphics/Graphics.js#L1148
Since: 3.0.0


fillPointShape

<instance> fillPointShape(point, [size])

Description:

Fill the given point.

Draws a square at the given position, 1 pixel in size by default.

Parameters:

nametypeoptionaldefaultdescription
pointPhaser.Math.Vector2NoThe point to fill.
sizenumberYes1The size of the square to draw.

Returns: Phaser.GameObjects.Graphics - This Game Object.

Source: src/gameobjects/graphics/Graphics.js#L887
Since: 3.0.0


fillRect

<instance> fillRect(x, y, width, height)

Description:

Fill a rectangle with the given position and size.

Parameters:

nametypeoptionaldescription
xnumberNoThe x coordinate of the top-left of the rectangle.
ynumberNoThe y coordinate of the top-left of the rectangle.
widthnumberNoThe width of the rectangle.
heightnumberNoThe height of the rectangle.

Returns: Phaser.GameObjects.Graphics - This Game Object.

Source: src/gameobjects/graphics/Graphics.js#L632
Since: 3.0.0


fillRectShape

<instance> fillRectShape(rect)

Description:

Fill the given rectangle.

Parameters:

nametypeoptionaldescription
rectPhaser.Geom.RectangleNoThe rectangle to fill.

Returns: Phaser.GameObjects.Graphics - This Game Object.

Source: src/gameobjects/graphics/Graphics.js#L602
Since: 3.0.0


fillRoundedRect

<instance> fillRoundedRect(x, y, width, height, [radius])

Description:

Fill a rounded rectangle with the given position, size and radius.

Parameters:

nametypeoptionaldefaultdescription
xnumberNoThe x coordinate of the top-left of the rectangle.
ynumberNoThe y coordinate of the top-left of the rectangle.
widthnumberNoThe width of the rectangle.
heightnumberNoThe height of the rectangle.
radiusPhaser.Types.GameObjects.Graphics.RoundedRectRadius | numberYes20The corner radius; It can also be an object to specify different radius for corners.

Returns: Phaser.GameObjects.Graphics - This Game Object.

Source: src/gameobjects/graphics/Graphics.js#L697
Since: 3.11.0


fillStyle

<instance> fillStyle(color, [alpha])

Description:

Set the current fill style. Used for all 'fill' related functions.

Parameters:

nametypeoptionaldefaultdescription
colornumberNoThe fill color.
alphanumberYes1The fill alpha.

Returns: Phaser.GameObjects.Graphics - This Game Object.

Source: src/gameobjects/graphics/Graphics.js#L315
Since: 3.0.0


fillTriangle

<instance> fillTriangle(x0, y0, x1, y1, x2, y2)

Description:

Fill a triangle with the given points.

Parameters:

nametypeoptionaldescription
x0numberNoThe x coordinate of the first point.
y0numberNoThe y coordinate of the first point.
x1numberNoThe x coordinate of the second point.
y1numberNoThe y coordinate of the second point.
x2numberNoThe x coordinate of the third point.
y2numberNoThe y coordinate of the third point.

Returns: Phaser.GameObjects.Graphics - This Game Object.

Source: src/gameobjects/graphics/Graphics.js#L969
Since: 3.0.0


fillTriangleShape

<instance> fillTriangleShape(triangle)

Description:

Fill the given triangle.

Parameters:

nametypeoptionaldescription
trianglePhaser.Geom.TriangleNoThe triangle to fill.

Returns: Phaser.GameObjects.Graphics - This Game Object.

Source: src/gameobjects/graphics/Graphics.js#L939
Since: 3.0.0


generateTexture

<instance> generateTexture(key, [width], [height])

Description:

Generate a texture from this Graphics object.

If key is a string it'll generate a new texture using it and add it into the

Texture Manager (assuming no key conflict happens).

If key is a Canvas it will draw the texture to that canvas context. Note that it will NOT

automatically upload it to the GPU in WebGL mode.

Please understand that the texture is created via the Canvas API of the browser, therefore some

Graphics features, such as fillGradientStyle, will not appear on the resulting texture,

as they're unsupported by the Canvas API.

Parameters:

nametypeoptionaldescription
keystring | HTMLCanvasElementNoThe key to store the texture with in the Texture Manager, or a Canvas to draw to.
widthnumberYesThe width of the graphics to generate.
heightnumberYesThe height of the graphics to generate.

Returns: Phaser.GameObjects.Graphics - This Game Object.

Source: src/gameobjects/graphics/Graphics.js#L1510
Since: 3.0.0


lineBetween

<instance> lineBetween(x1, y1, x2, y2)

Description:

Draw a line between the given points.

Parameters:

nametypeoptionaldescription
x1numberNoThe x coordinate of the start point of the line.
y1numberNoThe y coordinate of the start point of the line.
x2numberNoThe x coordinate of the end point of the line.
y2numberNoThe y coordinate of the end point of the line.

Returns: Phaser.GameObjects.Graphics - This Game Object.

Source: src/gameobjects/graphics/Graphics.js#L1034
Since: 3.0.0


lineGradientStyle

<instance> lineGradientStyle(lineWidth, topLeft, topRight, bottomLeft, bottomRight, [alpha])

Description:

Sets a gradient line style. This is a WebGL only feature.

The gradient color values represent the 4 corners of an untransformed rectangle.

The gradient is used to color all stroked shapes and paths drawn after calling this method.

If you wish to turn a gradient off, call lineStyle and provide a new single line color.

This feature is best used only on single lines. All other shapes will give strange results.

Note that for objects such as arcs or ellipses, or anything which is made out of triangles, each triangle used

will be filled with a gradient on its own. There is no ability to gradient stroke a shape or path as a single

entity at this time.

Tags:

  • webglOnly

Parameters:

nametypeoptionaldefaultdescription
lineWidthnumberNoThe stroke width.
topLeftnumberNoThe tint being applied to the top-left of the Game Object.
topRightnumberNoThe tint being applied to the top-right of the Game Object.
bottomLeftnumberNoThe tint being applied to the bottom-left of the Game Object.
bottomRightnumberNoThe tint being applied to the bottom-right of the Game Object.
alphanumberYes1The fill alpha.

Returns: Phaser.GameObjects.Graphics - This Game Object.

Source: src/gameobjects/graphics/Graphics.js#L384
Since: 3.12.0


lineStyle

<instance> lineStyle(lineWidth, color, [alpha])

Description:

Set the current line style. Used for all 'stroke' related functions.

Parameters:

nametypeoptionaldefaultdescription
lineWidthnumberNoThe stroke width.
colornumberNoThe stroke color.
alphanumberYes1The stroke alpha.

Returns: Phaser.GameObjects.Graphics - This Game Object.

Source: src/gameobjects/graphics/Graphics.js#L289
Since: 3.0.0


lineTo

<instance> lineTo(x, y)

Description:

Draw a line from the current drawing position to the given position.

Moves the current drawing position to the given position.

Parameters:

nametypeoptionaldescription
xnumberNoThe x coordinate to draw the line to.
ynumberNoThe y coordinate to draw the line to.

Returns: Phaser.GameObjects.Graphics - This Game Object.

Source: src/gameobjects/graphics/Graphics.js#L1057
Since: 3.0.0


moveTo

<instance> moveTo(x, y)

Description:

Move the current drawing position to the given position.

Parameters:

nametypeoptionaldescription
xnumberNoThe x coordinate to move to.
ynumberNoThe y coordinate to move to.

Returns: Phaser.GameObjects.Graphics - This Game Object.

Source: src/gameobjects/graphics/Graphics.js#L1080
Since: 3.0.0


preDestroy

<instance> preDestroy()

Description:

Internal destroy handler, called as part of the destroy process.

Access: protected

Source: src/gameobjects/graphics/Graphics.js#L1594
Since: 3.9.0


restore

<instance> restore()

Description:

Restores the most recently saved state of the Graphics by popping from the state stack.

Use Phaser.GameObjects.Graphics#save to save the current state, and call this afterwards to restore that state.

If there is no saved state, this command does nothing.

Returns: Phaser.GameObjects.Graphics - This Game Object.

Source: src/gameobjects/graphics/Graphics.js#L1384
Since: 3.0.0


rotateCanvas

<instance> rotateCanvas(radians)

Description:

Inserts a rotation command into this Graphics objects command buffer.

All objects drawn after calling this method will be rotated

by the given amount.

This does not change the rotation of the Graphics object itself,

only of the objects drawn by it after calling this method.

Parameters:

nametypeoptionaldescription
radiansnumberNoThe rotation angle, in radians.

Returns: Phaser.GameObjects.Graphics - This Game Object.

Source: src/gameobjects/graphics/Graphics.js#L1459
Since: 3.0.0


save

<instance> save()

Description:

Saves the state of the Graphics by pushing the current state onto a stack.

The most recently saved state can then be restored with Phaser.GameObjects.Graphics#restore.

Returns: Phaser.GameObjects.Graphics - This Game Object.

Source: src/gameobjects/graphics/Graphics.js#L1365
Since: 3.0.0


scaleCanvas

<instance> scaleCanvas(x, y)

Description:

Inserts a scale command into this Graphics objects command buffer.

All objects drawn after calling this method will be scaled

by the given amount.

This does not change the scale of the Graphics object itself,

only of the objects drawn by it after calling this method.

Parameters:

nametypeoptionaldescription
xnumberNoThe horizontal scale to apply.
ynumberNoThe vertical scale to apply.

Returns: Phaser.GameObjects.Graphics - This Game Object.

Source: src/gameobjects/graphics/Graphics.js#L1432
Since: 3.0.0


setDefaultStyles

<instance> setDefaultStyles(options)

Description:

Set the default style settings for this Graphics object.

Parameters:

nametypeoptionaldescription
optionsPhaser.Types.GameObjects.Graphics.StylesNoThe styles to set as defaults.

Returns: Phaser.GameObjects.Graphics - This Game Object.

Source: src/gameobjects/graphics/Graphics.js#L257
Since: 3.0.0


slice

<instance> slice(x, y, radius, startAngle, endAngle, [anticlockwise], [overshoot])

Description:

Creates a pie-chart slice shape centered at x, y with the given radius.

You must define the start and end angle of the slice.

Setting the anticlockwise argument to true creates a shape similar to Pacman.

Setting it to false creates a shape like a slice of pie.

This method will begin a new path and close the path at the end of it.

To display the actual slice you need to call either strokePath or fillPath after it.

Parameters:

nametypeoptionaldefaultdescription
xnumberNoThe horizontal center of the slice.
ynumberNoThe vertical center of the slice.
radiusnumberNoThe radius of the slice.
startAnglenumberNoThe start angle of the slice, given in radians.
endAnglenumberNoThe end angle of the slice, given in radians.
anticlockwisebooleanYesfalseWhether the drawing should be anticlockwise or clockwise.
overshootnumberYes0This value allows you to overshoot the endAngle by this amount. Useful if the arc has a thick stroke and needs to overshoot to join-up cleanly.

Returns: Phaser.GameObjects.Graphics - This Game Object.

Source: src/gameobjects/graphics/Graphics.js#L1326
Since: 3.4.0


stroke

<instance> stroke()

Description:

Stroke the current path.

This is an alias for Graphics.strokePath and does the same thing.

It was added to match the CanvasRenderingContext 2D API.

Returns: Phaser.GameObjects.Graphics - This Game Object.

Source: src/gameobjects/graphics/Graphics.js#L510
Since: 3.16.0


strokeCircle

<instance> strokeCircle(x, y, radius)

Description:

Stroke a circle with the given position and radius.

Parameters:

nametypeoptionaldescription
xnumberNoThe x coordinate of the center of the circle.
ynumberNoThe y coordinate of the center of the circle.
radiusnumberNoThe radius of the circle.

Returns: Phaser.GameObjects.Graphics - This Game Object.

Source: src/gameobjects/graphics/Graphics.js#L581
Since: 3.0.0


strokeCircleShape

<instance> strokeCircleShape(circle)

Description:

Stroke the given circle.

Parameters:

nametypeoptionaldescription
circlePhaser.Geom.CircleNoThe circle to stroke.

Returns: Phaser.GameObjects.Graphics - This Game Object.

Source: src/gameobjects/graphics/Graphics.js#L545
Since: 3.0.0


strokeEllipse

<instance> strokeEllipse(x, y, width, height, [smoothness])

Description:

Stroke an ellipse with the given position and size.

Parameters:

nametypeoptionaldefaultdescription
xnumberNoThe x coordinate of the center of the ellipse.
ynumberNoThe y coordinate of the center of the ellipse.
widthnumberNoThe width of the ellipse.
heightnumberNoThe height of the ellipse.
smoothnessnumberYes32The number of points to draw the ellipse with.

Returns: Phaser.GameObjects.Graphics - This Game Object.

Source: src/gameobjects/graphics/Graphics.js#L1215
Since: 3.0.0


strokeEllipseShape

<instance> strokeEllipseShape(ellipse, [smoothness])

Description:

Stroke the given ellipse.

Parameters:

nametypeoptionaldefaultdescription
ellipsePhaser.Geom.EllipseNoThe ellipse to stroke.
smoothnessnumberYes32The number of points to draw the ellipse with.

Returns: Phaser.GameObjects.Graphics - This Game Object.

Source: src/gameobjects/graphics/Graphics.js#L1195
Since: 3.0.0


strokeLineShape

<instance> strokeLineShape(line)

Description:

Draw the given line.

Parameters:

nametypeoptionaldescription
linePhaser.Geom.LineNoThe line to stroke.

Returns: Phaser.GameObjects.Graphics - This Game Object.

Source: src/gameobjects/graphics/Graphics.js#L1019
Since: 3.0.0


strokePath

<instance> strokePath()

Description:

Stroke the current path.

Returns: Phaser.GameObjects.Graphics - This Game Object.

Source: src/gameobjects/graphics/Graphics.js#L493
Since: 3.0.0


strokePoints

<instance> strokePoints(points, [closeShape], [closePath], [endIndex])

Description:

Stroke the shape represented by the given array of points.

Pass closeShape to automatically close the shape by joining the last to the first point.

Pass closePath to automatically close the path before it is stroked.

Parameters:

nametypeoptionaldefaultdescription
pointsArray.<Phaser.Math.Vector2>NoThe points to stroke.
closeShapebooleanYesfalseWhen true, the shape is closed by joining the last point to the first point.
closePathbooleanYesfalseWhen true, the path is closed before being stroked.
endIndexnumberYesThe index of points to stop drawing at. Defaults to points.length.

Returns: Phaser.GameObjects.Graphics - This Game Object.

Source: src/gameobjects/graphics/Graphics.js#L1101
Since: 3.0.0


strokeRect

<instance> strokeRect(x, y, width, height)

Description:

Stroke a rectangle with the given position and size.

Parameters:

nametypeoptionaldescription
xnumberNoThe x coordinate of the top-left of the rectangle.
ynumberNoThe y coordinate of the top-left of the rectangle.
widthnumberNoThe width of the rectangle.
heightnumberNoThe height of the rectangle.

Returns: Phaser.GameObjects.Graphics - This Game Object.

Source: src/gameobjects/graphics/Graphics.js#L655
Since: 3.0.0


strokeRectShape

<instance> strokeRectShape(rect)

Description:

Stroke the given rectangle.

Parameters:

nametypeoptionaldescription
rectPhaser.Geom.RectangleNoThe rectangle to stroke.

Returns: Phaser.GameObjects.Graphics - This Game Object.

Source: src/gameobjects/graphics/Graphics.js#L617
Since: 3.0.0


strokeRoundedRect

<instance> strokeRoundedRect(x, y, width, height, [radius])

Description:

Stroke a rounded rectangle with the given position, size and radius.

Parameters:

nametypeoptionaldefaultdescription
xnumberNoThe x coordinate of the top-left of the rectangle.
ynumberNoThe y coordinate of the top-left of the rectangle.
widthnumberNoThe width of the rectangle.
heightnumberNoThe height of the rectangle.
radiusPhaser.Types.GameObjects.Graphics.RoundedRectRadius | numberYes20The corner radius; It can also be an object to specify different radii for corners.

Returns: Phaser.GameObjects.Graphics - This Game Object.

Source: src/gameobjects/graphics/Graphics.js#L789
Since: 3.11.0


strokeTriangle

<instance> strokeTriangle(x0, y0, x1, y1, x2, y2)

Description:

Stroke a triangle with the given points.

Parameters:

nametypeoptionaldescription
x0numberNoThe x coordinate of the first point.
y0numberNoThe y coordinate of the first point.
x1numberNoThe x coordinate of the second point.
y1numberNoThe y coordinate of the second point.
x2numberNoThe x coordinate of the third point.
y2numberNoThe y coordinate of the third point.

Returns: Phaser.GameObjects.Graphics - This Game Object.

Source: src/gameobjects/graphics/Graphics.js#L994
Since: 3.0.0


strokeTriangleShape

<instance> strokeTriangleShape(triangle)

Description:

Stroke the given triangle.

Parameters:

nametypeoptionaldescription
trianglePhaser.Geom.TriangleNoThe triangle to stroke.

Returns: Phaser.GameObjects.Graphics - This Game Object.

Source: src/gameobjects/graphics/Graphics.js#L954
Since: 3.0.0


translateCanvas

<instance> translateCanvas(x, y)

Description:

Inserts a translation command into this Graphics objects command buffer.

All objects drawn after calling this method will be translated

by the given amount.

This does not change the position of the Graphics object itself,

only of the objects drawn by it after calling this method.

Parameters:

nametypeoptionaldescription
xnumberNoThe horizontal translation to apply.
ynumberNoThe vertical translation to apply.

Returns: Phaser.GameObjects.Graphics - This Game Object.

Source: src/gameobjects/graphics/Graphics.js#L1405
Since: 3.0.0