Class: Circle

Phaser.Geom. Circle

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.


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

Parameters:
Name Type Argument Default Description
x number <optional>
0

The x position of the center of the circle.

y number <optional>
0

The y position of the center of the circle.

radius number <optional>
0

The radius of the circle.

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

Members


bottom :number

The bottom position of the Circle.

Type:
  • number
Since: 3.0.0
Source: src/geom/circle/Circle.js (Line 346)

diameter :number

The diameter of the Circle.

Type:
  • number
Since: 3.0.0
Source: src/geom/circle/Circle.js (Line 261)

left :number

The left position of the Circle.

Type:
  • number
Since: 3.0.0
Source: src/geom/circle/Circle.js (Line 283)

radius :number

The radius of the Circle.

Type:
  • number
Since: 3.0.0
Source: src/geom/circle/Circle.js (Line 239)

The right position of the Circle.

Type:
  • number
Since: 3.0.0
Source: src/geom/circle/Circle.js (Line 304)

top :number

The top position of the Circle.

Type:
  • number
Since: 3.0.0
Source: src/geom/circle/Circle.js (Line 325)

<readonly> type :number

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)

x :number

The x position of the center of the circle.

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

y :number

The y position of the center of the circle.

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

Methods


<static> Area(circle)

Calculates the area of the circle.

Parameters:
Name Type Description
circle Phaser.Geom.Circle

The Circle to get the area of.

Since: 3.0.0
Source: src/geom/circle/Area.js (Line 7)
Returns:

The area of the Circle.

Type
number

<static> Circumference(circle)

Returns the circumference of the given Circle.

Parameters:
Name Type Description
circle Phaser.Geom.Circle

The Circle to get the circumference of.

Since: 3.0.0
Source: src/geom/circle/Circumference.js (Line 7)
Returns:

The circumference of the Circle.

Type
number

<static> CircumferencePoint(circle, angle [, out])

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

Parameters:
Name Type Argument 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 Phaser.Geom.Point | object <optional>

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

Since: 3.0.0
Source: src/geom/circle/CircumferencePoint.js (Line 9)
Returns:

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

Type
Phaser.Geom.Point | object

<static> Clone(source)

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

Parameters:
Name Type Description
source Phaser.Geom.Circle | object

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

Since: 3.0.0
Source: src/geom/circle/Clone.js (Line 9)
Returns:

A clone of the source Circle.

Type
Phaser.Geom.Circle

<static> Contains(circle, x, y)

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.

Since: 3.0.0
Source: src/geom/circle/Contains.js (Line 7)
Returns:

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

Type
boolean

<static> ContainsPoint(circle, point)

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

Parameters:
Name Type Description
circle Phaser.Geom.Circle

The Circle to check.

point Phaser.Geom.Point | object

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

Since: 3.0.0
Source: src/geom/circle/ContainsPoint.js (Line 9)
Returns:

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

Type
boolean

<static> ContainsRect(circle, rect)

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 Phaser.Geom.Rectangle | object

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

Since: 3.0.0
Source: src/geom/circle/ContainsRect.js (Line 9)
Returns:

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

Type
boolean

<static> CopyFrom(source, dest)

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.

Since: 3.0.0
Source: src/geom/circle/CopyFrom.js (Line 7)
Returns:

The destination Circle.

Type
Phaser.Geom.Circle

<static> Equals(circle, toCompare)

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.

Since: 3.0.0
Source: src/geom/circle/Equals.js (Line 7)
Returns:

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

Type
boolean

<static> GetBounds(circle [, out])

Returns the bounds of the Circle object.

Parameters:
Name Type Argument Description
circle Phaser.Geom.Circle

The Circle to get the bounds from.

out Phaser.Geom.Rectangle | object <optional>

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

Since: 3.0.0
Source: src/geom/circle/GetBounds.js (Line 9)
Returns:

The Rectangle object containing the Circles bounds.

Type
Phaser.Geom.Rectangle | object

<static> GetPoint(circle, position [, out])

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 Argument 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 Phaser.Geom.Point | object <optional>

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

Since: 3.0.0
Source: src/geom/circle/GetPoint.js (Line 12)
Returns:

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

Type
Phaser.Geom.Point | object

<static> GetPoints(circle, quantity [, stepRate] [, output])

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 Argument 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.

Since: 3.0.0
Source: src/geom/circle/GetPoints.js (Line 12)
Returns:

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

Type
Array.<Phaser.Geom.Point>

<static> Offset(circle, x, y)

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.

Since: 3.0.0
Source: src/geom/circle/Offset.js (Line 7)
Returns:

The Circle that was offset.

Type
Phaser.Geom.Circle

<static> OffsetPoint(circle, point)

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 Phaser.Geom.Point | object

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

Since: 3.0.0
Source: src/geom/circle/OffsetPoint.js (Line 7)
Returns:

The Circle that was offset.

Type
Phaser.Geom.Circle

<static> Random(circle [, out])

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

Parameters:
Name Type Argument Description
circle Phaser.Geom.Circle

The Circle to get a random point from.

out Phaser.Geom.Point | object <optional>

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

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

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

Type
Phaser.Geom.Point | object

contains(x, y)

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.

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

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

Type
boolean

getPoint(position [, out])

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 Argument 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 Phaser.Geom.Point | object <optional>

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

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

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

Type
Phaser.Geom.Point | object

getPoints(quantity [, stepRate] [, output])

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 Argument 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.

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

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

Type
array | Array.<Phaser.Geom.Point>

getRandomPoint( [point])

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

Parameters:
Name Type Argument Description
point Phaser.Geom.Point | object <optional>

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

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

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

Type
Phaser.Geom.Point | object

isEmpty()

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

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

True if the Circle is empty, otherwise false.

Type
boolean

setEmpty()

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

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

This Circle object.

Type
Phaser.Geom.Circle

setPosition( [x] [, y])

Sets the position of this Circle.

Parameters:
Name Type Argument Default Description
x number <optional>
0

The x position of the center of the circle.

y number <optional>
0

The y position of the center of the circle.

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

This Circle object.

Type
Phaser.Geom.Circle

setTo( [x] [, y] [, radius])

Sets the x, y and radius of this circle.

Parameters:
Name Type Argument Default Description
x number <optional>
0

The x position of the center of the circle.

y number <optional>
0

The y position of the center of the circle.

radius number <optional>
0

The radius of the circle.

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

This Circle object.

Type
Phaser.Geom.Circle