Phaser API Documentation

  Version: 
Filter

A Circle object.

This is a geometry object, containing numerical values and related methods to inspect and modify them. It is not a Game Object, in that you cannot add it to the display list, and it has no texture. To render a Circle you should look at the capabilities of the Graphics class.

Constructor:

new Circle([x], [y], [radius])

Parameters:

name type arguments description
x number <optional>

The x position of the center of the circle.

y number <optional>

The y position of the center of the circle.

radius number <optional>

The radius of the circle.

Since: 3.0.0
Source: src/geom/circle/Circle.js (Line 14)

Members

<private> _diameter: number
Focus
Focus

Description:

The internal diameter of the circle.

Type:
number
Since: 3.0.0
Source: src/geom/circle/Circle.js (Line 82)
Focus
Focus
<private> _radius: number
Focus
Focus

Description:

The internal radius of the circle.

Type:
number
Since: 3.0.0
Source: src/geom/circle/Circle.js (Line 72)
Focus
Focus
bottom: number
Focus
Focus

Description:

The bottom position of the Circle.

Type:
number
Since: 3.0.0
Focus
Focus
diameter: number
Focus
Focus

Description:

The diameter of the Circle.

Type:
number
Since: 3.0.0
Focus
Focus
left: number
Focus
Focus

Description:

The left position of the Circle.

Type:
number
Since: 3.0.0
Focus
Focus
radius: number
Focus
Focus

Description:

The radius of the Circle.

Type:
number
Since: 3.0.0
Focus
Focus
top: number
Focus
Focus

Description:

The top position of the Circle.

Type:
number
Since: 3.0.0
Focus
Focus
<readonly> type: number
Focus
Focus

Description:

The geometry constant type of this object: GEOM_CONST.CIRCLE. Used for fast type comparisons.

Type:
number
Since: 3.19.0
Source: src/geom/circle/Circle.js (Line 41)
Focus
Focus
x: number
Focus
Focus

Description:

The x position of the center of the circle.

Type:
number
Default: 0
Since: 3.0.0
Source: src/geom/circle/Circle.js (Line 52)
Focus
Focus
y: number
Focus
Focus

Description:

The y position of the center of the circle.

Type:
number
Default: 0
Since: 3.0.0
Source: src/geom/circle/Circle.js (Line 62)
Focus
Focus

Methods

contains(x, y)
Focus
Focus

Description:

Check to see if the Circle contains the given x / y coordinates.

Parameters:

name type description
x number

The x coordinate to check within the circle.

y number

The y coordinate to check within the circle.

Returns:
Description:

True if the coordinates are within the circle, otherwise false.

Type:
  • boolean
Since: 3.0.0
Source: src/geom/circle/Circle.js (Line 93)
Focus
Focus
getPoint(position, [out])
Focus
Focus

Description:

Returns a Point object containing the coordinates of a point on the circumference of the Circle based on the given angle normalized to the range 0 to 1. I.e. a value of 0.5 will give the point at 180 degrees around the circle.

Parameters:

name type arguments description
position number

A value between 0 and 1, where 0 equals 0 degrees, 0.5 equals 180 degrees and 1 equals 360 around the circle.

out object | Phaser.Geom.Point <optional>

An object to store the return values in. If not given a Point object will be created.

Returns:
Description:

A Point, or point-like object, containing the coordinates of the point around the circle.

Type:
Since: 3.0.0
Focus
Focus
getPoints(quantity, [stepRate], [output])
Focus
Focus

Description:

Returns an array of Point objects containing the coordinates of the points around the circumference of the Circle, based on the given quantity or stepRate values.

Parameters:

name type arguments description
quantity number

The amount of points to return. If a falsey value the quantity will be derived from the stepRate instead.

stepRate number <optional>

Sets the quantity by getting the circumference of the circle and dividing it by the stepRate.

output array | Array.<Phaser.Geom.Point> <optional>

An array to insert the points in to. If not provided a new array will be created.

Returns:
Description:

An array of Point objects pertaining to the points around the circumference of the circle.

Type:
Since: 3.0.0
Focus
Focus
getRandomPoint([point])
Focus
Focus

Description:

Returns a uniformly distributed random point from anywhere within the Circle.

Parameters:

name type arguments description
point object | Phaser.Geom.Point <optional>

A Point or point-like object to set the random x and y values in.

Returns:
Description:

A Point object with the random values set in the x and y properties.

Type:
Since: 3.0.0
Focus
Focus
isEmpty()
Focus
Focus

Description:

Checks to see if the Circle is empty: has a radius of zero.

Returns:
Description:

True if the Circle is empty, otherwise false.

Type:
  • boolean
Since: 3.0.0
Focus
Focus
setEmpty()
Focus
Focus

Description:

Sets this Circle to be empty with a radius of zero. Does not change its position.

Returns:
Description:

This Circle object.

Since: 3.0.0
Focus
Focus
setPosition([x], [y])
Focus
Focus

Description:

Sets the position of this Circle.

Parameters:

name type arguments description
x number <optional>

The x position of the center of the circle.

y number <optional>

The y position of the center of the circle.

Returns:
Description:

This Circle object.

Since: 3.0.0
Focus
Focus
setTo([x], [y], [radius])
Focus
Focus

Description:

Sets the x, y and radius of this circle.

Parameters:

name type arguments description
x number <optional>

The x position of the center of the circle.

y number <optional>

The y position of the center of the circle.

radius number <optional>

The radius of the circle.

Returns:
Description:

This Circle object.

Since: 3.0.0
Focus
Focus
<static> Area(circle)
Focus
Focus

Description:

Calculates the area of the circle.

Parameters:

name type description
circle Phaser.Geom.Circle

The Circle to get the area of.

Returns:
Description:

The area of the Circle.

Type:
  • number
Since: 3.0.0
Source: src/geom/circle/Area.js (Line 7)
Focus
Focus
<static> Circumference(circle)
Focus
Focus

Description:

Returns the circumference of the given Circle.

Parameters:

name type description
circle Phaser.Geom.Circle

The Circle to get the circumference of.

Returns:
Description:

The circumference of the Circle.

Type:
  • number
Since: 3.0.0
Focus
Focus
<static> CircumferencePoint(circle, angle, [out])
Focus
Focus

Description:

Returns a Point object containing the coordinates of a point on the circumference of the Circle based on the given angle.

Parameters:

name type arguments description
circle Phaser.Geom.Circle

The Circle to get the circumference point on.

angle number

The angle from the center of the Circle to the circumference to return the point from. Given in radians.

out object | Phaser.Geom.Point <optional>

A Point, or point-like object, to store the results in. If not given a Point will be created.

Returns:
Description:

A Point object where the x and y properties are the point on the circumference.

Type:
Since: 3.0.0
Focus
Focus
<static> Clone(source)
Focus
Focus

Description:

Creates a new Circle instance based on the values contained in the given source.

Parameters:

name type description
source object | Phaser.Geom.Circle

The Circle to be cloned. Can be an instance of a Circle or a circle-like object, with x, y and radius properties.

Returns:
Description:

A clone of the source Circle.

Since: 3.0.0
Source: src/geom/circle/Clone.js (Line 9)
Focus
Focus
<static> Contains(circle, x, y)
Focus
Focus

Description:

Check to see if the Circle contains the given x / y coordinates.

Parameters:

name type description
circle Phaser.Geom.Circle

The Circle to check.

x number

The x coordinate to check within the circle.

y number

The y coordinate to check within the circle.

Returns:
Description:

True if the coordinates are within the circle, otherwise false.

Type:
  • boolean
Since: 3.0.0
Focus
Focus
<static> ContainsPoint(circle, point)
Focus
Focus

Description:

Check to see if the Circle contains the given Point object.

Parameters:

name type description
circle Phaser.Geom.Circle

The Circle to check.

point object | Phaser.Geom.Point

The Point object to check if it's within the Circle or not.

Returns:
Description:

True if the Point coordinates are within the circle, otherwise false.

Type:
  • boolean
Since: 3.0.0
Focus
Focus
<static> ContainsRect(circle, rect)
Focus
Focus

Description:

Check to see if the Circle contains all four points of the given Rectangle object.

Parameters:

name type description
circle Phaser.Geom.Circle

The Circle to check.

rect object | Phaser.Geom.Rectangle

The Rectangle object to check if it's within the Circle or not.

Returns:
Description:

True if all of the Rectangle coordinates are within the circle, otherwise false.

Type:
  • boolean
Since: 3.0.0
Focus
Focus
<static> CopyFrom(source, dest)
Focus
Focus

Description:

Copies the x, y and radius properties from the source Circle into the given dest Circle, then returns the dest Circle.

Parameters:

name type description
source Phaser.Geom.Circle

The source Circle to copy the values from.

dest Phaser.Geom.Circle

The destination Circle to copy the values to.

Returns:
Description:

The destination Circle.

Since: 3.0.0
Focus
Focus
<static> Equals(circle, toCompare)
Focus
Focus

Description:

Compares the x, y and radius properties of the two given Circles. Returns true if they all match, otherwise returns false.

Parameters:

name type description
circle Phaser.Geom.Circle

The first Circle to compare.

toCompare Phaser.Geom.Circle

The second Circle to compare.

Returns:
Description:

true if the two Circles equal each other, otherwise false.

Type:
  • boolean
Since: 3.0.0
Source: src/geom/circle/Equals.js (Line 7)
Focus
Focus
<static> GetBounds(circle, [out])
Focus
Focus

Description:

Returns the bounds of the Circle object.

Parameters:

name type arguments description
circle Phaser.Geom.Circle

The Circle to get the bounds from.

out object | Phaser.Geom.Rectangle <optional>

A Rectangle, or rectangle-like object, to store the circle bounds in. If not given a new Rectangle will be created.

Returns:
Description:

The Rectangle object containing the Circles bounds.

Type:
Since: 3.0.0
Focus
Focus
<static> GetPoint(circle, position, [out])
Focus
Focus

Description:

Returns a Point object containing the coordinates of a point on the circumference of the Circle based on the given angle normalized to the range 0 to 1. I.e. a value of 0.5 will give the point at 180 degrees around the circle.

Parameters:

name type arguments description
circle Phaser.Geom.Circle

The Circle to get the circumference point on.

position number

A value between 0 and 1, where 0 equals 0 degrees, 0.5 equals 180 degrees and 1 equals 360 around the circle.

out object | Phaser.Geom.Point <optional>

An object to store the return values in. If not given a Point object will be created.

Returns:
Description:

A Point, or point-like object, containing the coordinates of the point around the circle.

Type:
Since: 3.0.0
Focus
Focus
<static> GetPoints(circle, quantity, [stepRate], [output])
Focus
Focus

Description:

Returns an array of Point objects containing the coordinates of the points around the circumference of the Circle, based on the given quantity or stepRate values.

Parameters:

name type arguments description
circle Phaser.Geom.Circle

The Circle to get the points from.

quantity number

The amount of points to return. If a falsey value the quantity will be derived from the stepRate instead.

stepRate number <optional>

Sets the quantity by getting the circumference of the circle and dividing it by the stepRate.

output array <optional>

An array to insert the points in to. If not provided a new array will be created.

Returns:
Description:

An array of Point objects pertaining to the points around the circumference of the circle.

Type:
Since: 3.0.0
Focus
Focus
<static> Offset(circle, x, y)
Focus
Focus

Description:

Offsets the Circle by the values given.

Parameters:

name type description
circle Phaser.Geom.Circle

The Circle to be offset (translated.)

x number

The amount to horizontally offset the Circle by.

y number

The amount to vertically offset the Circle by.

Returns:
Description:

The Circle that was offset.

Since: 3.0.0
Source: src/geom/circle/Offset.js (Line 7)
Focus
Focus
<static> OffsetPoint(circle, point)
Focus
Focus

Description:

Offsets the Circle by the values given in the x and y properties of the Point object.

Parameters:

name type description
circle Phaser.Geom.Circle

The Circle to be offset (translated.)

point object | Phaser.Geom.Point

The Point object containing the values to offset the Circle by.

Returns:
Description:

The Circle that was offset.

Since: 3.0.0
Focus
Focus
<static> Random(circle, [out])
Focus
Focus

Description:

Returns a uniformly distributed random point from anywhere within the given Circle.

Parameters:

name type arguments description
circle Phaser.Geom.Circle

The Circle to get a random point from.

out object | Phaser.Geom.Point <optional>

A Point or point-like object to set the random x and y values in.

Returns:
Description:

A Point object with the random values set in the x and y properties.

Type:
Since: 3.0.0
Source: src/geom/circle/Random.js (Line 9)
Focus
Focus