Skip to main content
Version: Phaser v4.0.0

Ellipse

An Ellipse object.

An Ellipse is defined by its center position (x, y), a total width, and a total height. It can be used for geometric intersection tests (point-in-ellipse containment), sampling evenly-spaced or random points on its circumference or interior, and as a lightweight shape descriptor for collision or hit-area purposes.

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 an Ellipse you should look at the capabilities of the Graphics class.

Constructor

new Ellipse([x], [y], [width], [height])

Parameters

nametypeoptionaldefaultdescription
xnumberYes0The x position of the center of the ellipse.
ynumberYes0The y position of the center of the ellipse.
widthnumberYes0The width of the ellipse.
heightnumberYes0The height of the ellipse.

Scope: static

Source: src/geom/ellipse/Ellipse.js#L14
Since: 3.0.0

Public Methods

Area

<static> Area(ellipse)

Description:

Calculates the area of the given Ellipse using the formula: π × majorRadius × minorRadius. Returns 0 if the Ellipse is empty (i.e. has no width or height).

Parameters:

nametypeoptionaldescription
ellipsePhaser.Geom.EllipseNoThe Ellipse to get the area of.

Returns: number - The area of the Ellipse, or 0 if the Ellipse is empty.

Source: src/geom/ellipse/Area.js#L7
Since: 3.0.0


Circumference

<static> Circumference(ellipse)

Description:

Returns the circumference of the given Ellipse.

Parameters:

nametypeoptionaldescription
ellipsePhaser.Geom.EllipseNoThe Ellipse to get the circumference of.

Returns: number - The circumference of the Ellipse.

Source: src/geom/ellipse/Circumference.js#L7
Since: 3.0.0


CircumferencePoint

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

Description:

Returns a Vector2 containing the coordinates of a point on the circumference of the Ellipse based on the given angle.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
ellipsePhaser.Geom.EllipseNoThe Ellipse to get the circumference point on.
anglenumberNoThe angle from the center of the Ellipse to the circumference to return the point from. Given in radians.
outPhaser.Math.Vector2YesA Vector2 to store the results in. If not given a Vector2 will be created.

Returns: Phaser.Math.Vector2 - A Vector2 object where the x and y properties are the point on the circumference.

Source: src/geom/ellipse/CircumferencePoint.js#L9
Since: 3.0.0


Clone

<static> Clone(source)

Description:

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

Parameters:

nametypeoptionaldescription
sourcePhaser.Geom.EllipseNoThe Ellipse to be cloned. Can be an instance of an Ellipse or an ellipse-like object, with x, y, width and height properties.

Returns: Phaser.Geom.Ellipse - A clone of the source Ellipse.

Source: src/geom/ellipse/Clone.js#L9
Since: 3.0.0


contains

<instance> contains(x, y)

Description:

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

Parameters:

nametypeoptionaldescription
xnumberNoThe x coordinate to check within the ellipse.
ynumberNoThe y coordinate to check within the ellipse.

Returns: boolean - True if the coordinates are within the ellipse, otherwise false.

Source: src/geom/ellipse/Ellipse.js#L100
Since: 3.0.0


Contains

<static> Contains(ellipse, x, y)

Description:

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

Parameters:

nametypeoptionaldescription
ellipsePhaser.Geom.EllipseNoThe Ellipse to check.
xnumberNoThe x coordinate to check within the ellipse.
ynumberNoThe y coordinate to check within the ellipse.

Returns: boolean - True if the coordinates are within the ellipse, otherwise false.

Source: src/geom/ellipse/Contains.js#L7
Since: 3.0.0


ContainsPoint

<static> ContainsPoint(ellipse, vec)

Description:

Check to see if the Ellipse contains the given x and y coordinates as stored in the Vector2.

Parameters:

nametypeoptionaldescription
ellipsePhaser.Geom.EllipseNoThe Ellipse to check.
vecPhaser.Math.Vector2NoThe Vector2 object to check if its coordinates are within the Ellipse or not.

Returns: boolean - True if the Vector2 coordinates are within the ellipse, otherwise false.

Source: src/geom/ellipse/ContainsPoint.js#L9
Since: 3.0.0


ContainsRect

<static> ContainsRect(ellipse, rect)

Description:

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

Parameters:

nametypeoptionaldescription
ellipsePhaser.Geom.EllipseNoThe Ellipse to check.
rectPhaser.Geom.Rectangle | objectNoThe Rectangle object to check if it's within the Ellipse or not.

Returns: boolean - True if all of the Rectangle coordinates are within the ellipse, otherwise false.

Source: src/geom/ellipse/ContainsRect.js#L9
Since: 3.0.0


CopyFrom

<static> CopyFrom(source, dest)

Description:

Copies the x, y, width and height properties from the source Ellipse into the given dest Ellipse, then returns the dest Ellipse.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
sourcePhaser.Geom.EllipseNoThe source Ellipse to copy the values from.
destPhaser.Geom.EllipseNoThe destination Ellipse to copy the values to.

Returns: Phaser.Geom.Ellipse - The destination Ellipse.

Source: src/geom/ellipse/CopyFrom.js#L7
Since: 3.0.0


Equals

<static> Equals(ellipse, toCompare)

Description:

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

Parameters:

nametypeoptionaldescription
ellipsePhaser.Geom.EllipseNoThe first Ellipse to compare.
toComparePhaser.Geom.EllipseNoThe second Ellipse to compare.

Returns: boolean - true if the two Ellipse equal each other, otherwise false.

Source: src/geom/ellipse/Equals.js#L7
Since: 3.0.0


GetBounds

<static> GetBounds(ellipse, [out])

Description:

Returns the bounds of the Ellipse object.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
ellipsePhaser.Geom.EllipseNoThe Ellipse to get the bounds from.
outPhaser.Geom.Rectangle | objectYesA Rectangle, or rectangle-like object, to store the ellipse bounds in. If not given a new Rectangle will be created.

Returns: Phaser.Geom.Rectangle, object - The Rectangle object containing the Ellipse bounds.

Source: src/geom/ellipse/GetBounds.js#L9
Since: 3.0.0


getMajorRadius

<instance> getMajorRadius()

Description:

Returns the major radius of the ellipse. Also known as the Semi Major Axis.

Returns: number - The major radius.

Source: src/geom/ellipse/Ellipse.js#L283
Since: 3.0.0


getMinorRadius

<instance> getMinorRadius()

Description:

Returns the minor radius of the ellipse. Also known as the Semi Minor Axis.

Returns: number - The minor radius.

Source: src/geom/ellipse/Ellipse.js#L270
Since: 3.0.0


getPoint

<instance> getPoint(position, [point])

Description:

Returns a Vector2 object containing the coordinates of a point on the circumference of the Ellipse 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 ellipse.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
positionnumberNoA value between 0 and 1, where 0 equals 0 degrees, 0.5 equals 180 degrees and 1 equals 360 around the ellipse.
pointPhaser.Math.Vector2YesA Vector2 to store the return values in. If not given a Vector2 object will be created.

Returns: Phaser.Math.Vector2 - A Vector2 instance containing the coordinates of the point around the ellipse.

Source: src/geom/ellipse/Ellipse.js#L116
Since: 3.0.0


GetPoint

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

Description:

Returns a Vector2 object containing the coordinates of a point on the circumference of the Ellipse 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 ellipse.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
ellipsePhaser.Geom.EllipseNoThe Ellipse to get the circumference point on.
positionnumberNoA value between 0 and 1, where 0 equals 0 degrees, 0.5 equals 180 degrees and 1 equals 360 degrees around the ellipse.
outPhaser.Math.Vector2YesA Vector2 object to store the return values in. If not given a new Vector2 object will be created.

Returns: Phaser.Math.Vector2 - A Vector2 object, containing the coordinates of the point around the ellipse.

Source: src/geom/ellipse/GetPoint.js#L12
Since: 3.0.0


getPoints

<instance> getPoints(quantity, [stepRate], [output])

Description:

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

Tags:

  • generic

Parameters:

nametypeoptionaldescription
quantitynumberNoThe amount of points to return. If a falsey value the quantity will be derived from the stepRate instead.
stepRatenumberYesSets the quantity by getting the circumference of the ellipse and dividing it by the stepRate.
outputArray.<Phaser.Math.Vector2>YesAn array to insert the Vector2s in. If not provided a new array will be created.

Returns: Array.<Phaser.Math.Vector2> - An array of Vector2 objects pertaining to the points around the circumference of the ellipse.

Source: src/geom/ellipse/Ellipse.js#L136
Since: 3.0.0


GetPoints

<static> GetPoints(ellipse, quantity, [stepRate], [out])

Description:

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

Tags:

  • generic

Parameters:

nametypeoptionaldescription
ellipsePhaser.Geom.EllipseNoThe Ellipse to get the points from.
quantitynumberNoThe amount of points to return. If a falsy value the quantity will be derived from the stepRate instead.
stepRatenumberYesSets the quantity by getting the circumference of the ellipse and dividing it by the stepRate.
outArray.<Phaser.Math.Vector2>YesAn array to insert the Vector2 objects into. If not provided a new array will be created.

Returns: Array.<Phaser.Math.Vector2> - An array of Vector2 objects pertaining to the points around the circumference of the ellipse.

Source: src/geom/ellipse/GetPoints.js#L12
Since: 3.0.0


getRandomPoint

<instance> getRandomPoint([vec])

Description:

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

Tags:

  • generic

Parameters:

nametypeoptionaldescription
vecPhaser.Math.Vector2YesA Vector2 object to set the random x and y values in.

Returns: Phaser.Math.Vector2 - A Vector2 object with the random values set in the x and y properties.

Source: src/geom/ellipse/Ellipse.js#L156
Since: 3.0.0


isEmpty

<instance> isEmpty()

Description:

Checks to see if the Ellipse is empty: has a width or height of zero or less.

Returns: boolean - True if the Ellipse is empty, otherwise false.

Source: src/geom/ellipse/Ellipse.js#L257
Since: 3.0.0


Offset

<static> Offset(ellipse, x, y)

Description:

Offsets the Ellipse by the values given.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
ellipsePhaser.Geom.EllipseNoThe Ellipse to be offset (translated).
xnumberNoThe amount to horizontally offset the Ellipse by.
ynumberNoThe amount to vertically offset the Ellipse by.

Returns: Phaser.Geom.Ellipse - The Ellipse that was offset.

Source: src/geom/ellipse/Offset.js#L7
Since: 3.0.0


OffsetPoint

<static> OffsetPoint(ellipse, vec)

Description:

Offsets the Ellipse by the values given in the x and y properties of the Vector2 object.

Tags:

  • generic

Parameters:

nametypeoptionaldescription
ellipsePhaser.Geom.EllipseNoThe Ellipse to be offset (translated.)
vecPhaser.Math.Vector2NoThe Vector2 object containing the values to offset the Ellipse by.

Returns: Phaser.Geom.Ellipse - The Ellipse that was offset.

Source: src/geom/ellipse/OffsetPoint.js#L7
Since: 3.0.0


Random

<static> Random(ellipse, [out])

Description:

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

Tags:

  • generic

Parameters:

nametypeoptionaldescription
ellipsePhaser.Geom.EllipseNoThe Ellipse to get a random point from.
outPhaser.Math.Vector2YesA Vector2 object to set the random x and y values in.

Returns: Phaser.Math.Vector2 - A Vector2 object with the random values set in the x and y properties.

Source: src/geom/ellipse/Random.js#L9
Since: 3.0.0


setEmpty

<instance> setEmpty()

Description:

Sets this Ellipse to be empty with a width and height of zero. Does not change its position.

Returns: Phaser.Geom.Ellipse - This Ellipse object.

Source: src/geom/ellipse/Ellipse.js#L196
Since: 3.0.0


setPosition

<instance> setPosition(x, y)

Description:

Sets the position of this Ellipse. If the y argument is omitted, both the x and y positions will be set to the value of x.

Parameters:

nametypeoptionaldescription
xnumberNoThe x position of the center of the ellipse.
ynumberNoThe y position of the center of the ellipse.

Returns: Phaser.Geom.Ellipse - This Ellipse object.

Source: src/geom/ellipse/Ellipse.js#L213
Since: 3.0.0


setSize

<instance> setSize(width, [height])

Description:

Sets the size of this Ellipse. Does not change its position. If the height argument is omitted it will be set equal to width, producing a circle.

Parameters:

nametypeoptionaldefaultdescription
widthnumberNoThe width of the ellipse.
heightnumberYes"width"The height of the ellipse.

Returns: Phaser.Geom.Ellipse - This Ellipse object.

Source: src/geom/ellipse/Ellipse.js#L235
Since: 3.0.0


setTo

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

Description:

Sets the x, y, width and height of this ellipse.

Parameters:

nametypeoptionaldescription
xnumberNoThe x position of the center of the ellipse.
ynumberNoThe y position of the center of the ellipse.
widthnumberNoThe width of the ellipse.
heightnumberNoThe height of the ellipse.

Returns: Phaser.Geom.Ellipse - This Ellipse object.

Source: src/geom/ellipse/Ellipse.js#L173
Since: 3.0.0


Public Members

bottom

bottom: number

Description:

The bottom position of the Ellipse.

Source: src/geom/ellipse/Ellipse.js#L359
Since: 3.0.0


height

height: number

Description:

The height of the ellipse.

Source: src/geom/ellipse/Ellipse.js#L89
Since: 3.0.0


left

left: number

Description:

The left position of the Ellipse.

Source: src/geom/ellipse/Ellipse.js#L296
Since: 3.0.0


right: number

Description:

The right position of the Ellipse.

Source: src/geom/ellipse/Ellipse.js#L317
Since: 3.0.0


top

top: number

Description:

The top position of the Ellipse.

Source: src/geom/ellipse/Ellipse.js#L338
Since: 3.0.0


type

type: number

Description:

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

Source: src/geom/ellipse/Ellipse.js#L48
Since: 3.19.0


width

width: number

Description:

The width of the ellipse.

Source: src/geom/ellipse/Ellipse.js#L79
Since: 3.0.0


x

x: number

Description:

The x position of the center of the ellipse.

Source: src/geom/ellipse/Ellipse.js#L59
Since: 3.0.0


y

y: number

Description:

The y position of the center of the ellipse.

Source: src/geom/ellipse/Ellipse.js#L69
Since: 3.0.0