# Phaser API Documentation

Version:
This is a beta release of our new docs system. Found an issue?
Please tell us about it in the #ðŸ“–-newdocs-feedback channel on the Phaser Discord

# Phaser . Curves . Ellipse

An Elliptical Curve derived from the Base Curve class.

See https://en.wikipedia.org/wiki/Elliptic_curve for more details.

### Constructor:

``````new Ellipse([x], [y], [xRadius], [yRadius], [startAngle], [endAngle], [clockwise], [rotation])
``````

#### Parameters:

name type arguments Default description
x number | Phaser.Types.Curves.EllipseCurveConfig <optional> 0

The x coordinate of the ellipse, or an Ellipse Curve configuration object.

y number <optional> 0

The y coordinate of the ellipse.

startAngle number <optional> 0

The start angle of the ellipse, in degrees.

endAngle number <optional> 360

The end angle of the ellipse, in degrees.

clockwise boolean <optional> false

Whether the ellipse angles are given as clockwise (`true`) or counter-clockwise (`false`).

rotation number <optional> 0

The rotation of the ellipse, in degrees.

Since: 3.0.0

## Members

<private> _clockwise: boolean

#### Description:

Anti-clockwise direction.

##### Type:
boolean
Since: 3.0.0
<private> _endAngle: number

#### Description:

The end angle of the ellipse in radians.

##### Type:
number
Since: 3.0.0
<private> _rotation: number

#### Description:

The rotation of the arc.

##### Type:
number
Since: 3.0.0
<private> _startAngle: number

#### Description:

The starting angle of the ellipse in radians.

##### Type:
number
Since: 3.0.0
<private> _tmpVec2A: Phaser.Math.Vector2

#### Description:

A temporary calculation Vector.

##### Type:
Inherited from: Phaser.Curves.Curve#_tmpVec2A
Since: 3.0.0
Source: src/curves/Curve.js (Line 90)
<private> _tmpVec2B: Phaser.Math.Vector2

#### Description:

A temporary calculation Vector.

##### Type:
Inherited from: Phaser.Curves.Curve#_tmpVec2B
Since: 3.0.0
Source: src/curves/Curve.js (Line 100)

#### Description:

The horizontal radius of the ellipse.

number
Since: 3.0.0

#### Description:

The vertical radius of the ellipse.

number
Since: 3.0.0
active: boolean

#### Description:

For a curve on a Path, `false` means the Path will ignore this curve.

##### Type:
boolean
Default: true
Inherited from: Phaser.Curves.Curve#active
Since: 3.0.0
Source: src/curves/Curve.js (Line 80)
angle: number

#### Description:

The rotation of the ellipse, relative to the center, in degrees.

##### Type:
number
Since: 3.14.0
arcLengthDivisions: number

#### Description:

The quantity of arc length divisions within the curve.

##### Type:
number
Default: 100
Inherited from: Phaser.Curves.Curve#arcLengthDivisions
Since: 3.0.0
Source: src/curves/Curve.js (Line 50)
cacheArcLengths: Array.<number>

#### Description:

An array of cached arc length values.

##### Type:
Array.<number>
Default: []
Inherited from: Phaser.Curves.Curve#cacheArcLengths
Since: 3.0.0
Source: src/curves/Curve.js (Line 60)
clockwise: boolean

#### Description:

`true` if the ellipse rotation is clockwise or `false` if anti-clockwise.

##### Type:
boolean
Since: 3.0.0
defaultDivisions: number

#### Description:

The default number of divisions within the curve.

##### Type:
number
Default: 5
Inherited from: Phaser.Curves.Curve#defaultDivisions
Since: 3.0.0
Source: src/curves/Curve.js (Line 40)
endAngle: number

#### Description:

The end angle of the ellipse in degrees.

##### Type:
number
Since: 3.0.0
needsUpdate: boolean

#### Description:

Does the data of this curve need updating?

##### Type:
boolean
Default: true
Inherited from: Phaser.Curves.Curve#needsUpdate
Since: 3.0.0
Source: src/curves/Curve.js (Line 70)

#### Description:

The center point of the ellipse. Used for calculating rotation.

Since: 3.0.0
rotation: number

#### Description:

The rotation of the ellipse, relative to the center, in radians.

##### Type:
number
Since: 3.0.0
startAngle: number

#### Description:

The start angle of the ellipse in degrees.

number
Since: 3.0.0
type: string

#### Description:

String based identifier for the type of curve.

##### Type:
string
Inherited from: Phaser.Curves.Curve#type
Since: 3.0.0
Source: src/curves/Curve.js (Line 31)
x: number

#### Description:

The x coordinate of the center of the ellipse.

number
Since: 3.0.0

#### Description:

The horizontal radius of the ellipse.

number
Since: 3.0.0
y: number

#### Description:

The y coordinate of the center of the ellipse.

number
Since: 3.0.0

#### Description:

The vertical radius of the ellipse.

number
Since: 3.0.0

## Methods

draw(graphics, [pointsTotal])

#### Description:

Draws this curve on the given Graphics object.

The curve is drawn using `Graphics.strokePoints` so will be drawn at whatever the present Graphics stroke color is. The Graphics object is not cleared before the draw, so the curve will appear on-top of anything else already rendered to it.

#### Parameters:

name type arguments Default description
graphics Phaser.GameObjects.Graphics

The Graphics instance onto which this curve will be drawn.

pointsTotal number <optional> 32

The resolution of the curve. The higher the value the smoother it will render, at the cost of rendering performance.

##### Description:

The Graphics object to which the curve was drawn.

##### Type:
Inherited from: Phaser.Curves.Curve#draw
Since: 3.0.0
Source: src/curves/Curve.js (Line 111)
getBounds([out], [accuracy])

#### Description:

Returns a Rectangle where the position and dimensions match the bounds of this Curve.

You can control the accuracy of the bounds. The value given is used to work out how many points to plot across the curve. Higher values are more accurate at the cost of calculation speed.

#### Parameters:

name type arguments Default description
out Phaser.Geom.Rectangle <optional>

The Rectangle to store the bounds in. If falsey a new object will be created.

accuracy number <optional> 16

The accuracy of the bounds calculations.

##### Description:

A Rectangle object holding the bounds of this curve. If `out` was given it will be this object.

##### Type:
Inherited from: Phaser.Curves.Curve#getBounds
Since: 3.0.0
Source: src/curves/Curve.js (Line 135)
getDistancePoints(distance)

#### Description:

Returns an array of points, spaced out X distance pixels apart. The smaller the distance, the larger the array will be.

#### Parameters:

name type description
distance number

The distance, in pixels, between each point along the curve.

##### Description:

An Array of Point objects.

##### Type:
Inherited from: Phaser.Curves.Curve#getDistancePoints
Since: 3.0.0
Source: src/curves/Curve.js (Line 169)
getEndPoint([out])

#### Description:

Get a point at the end of the curve.

#### Parameters:

name type arguments description
out Phaser.Math.Vector2 <optional>

Optional Vector object to store the result in.

##### Description:

Vector2 containing the coordinates of the curves end point.

##### Type:
Inherited from: Phaser.Curves.Curve#getEndPoint
Since: 3.0.0
Source: src/curves/Curve.js (Line 189)
getLength()

#### Description:

Get total curve arc length

##### Description:

The total length of the curve.

##### Type:
• number
Inherited from: Phaser.Curves.Curve#getLength
Since: 3.0.0
Source: src/curves/Curve.js (Line 206)
getLengths([divisions])

#### Description:

Get a list of cumulative segment lengths.

These lengths are

• [0] 0
• [1] The first segment
• [2] The first and second segment
• ...
• [divisions] All segments

#### Parameters:

name type arguments description
divisions number <optional>

The number of divisions or segments.

##### Description:

An array of cumulative lengths.

##### Type:
• Array.<number>
Inherited from: Phaser.Curves.Curve#getLengths
Since: 3.0.0
Source: src/curves/Curve.js (Line 222)
getPoint(t, [out])

#### Description:

Get point at relative position in curve according to length.

#### Parameters:

name type arguments description
t number

The position along the curve to return. Where 0 is the start and 1 is the end.

out Phaser.Math.Vector2 <optional>

A Vector2 object to store the result in. If not given will be created.

##### Description:

The coordinates of the point on the curve. If an `out` object was given this will be returned.

##### Type:
Since: 3.0.0
getPointAt(u, [out])

#### Description:

Get a point at a relative position on the curve, by arc length.

#### Parameters:

name type arguments description
u number

The relative position, [0..1].

out Phaser.Math.Vector2 <optional>

A point to store the result in.

The point.

##### Type:
Inherited from: Phaser.Curves.Curve#getPointAt
Since: 3.0.0
Source: src/curves/Curve.js (Line 278)
getPoints([divisions], [stepRate], [out])

#### Description:

Get a sequence of evenly spaced points from the curve.

You can pass `divisions`, `stepRate`, or neither.

The number of divisions will be

1. `divisions`, if `divisions` > 0; or
2. `this.getLength / stepRate`, if `stepRate` > 0; or
3. `this.defaultDivisions`

`1 + divisions` points will be returned.

#### Parameters:

name type arguments description
divisions number <optional>

The number of divisions to make.

stepRate number <optional>

The curve distance between points, implying `divisions`.

out array | Array.<Phaser.Math.Vector2> <optional>

An optional array to store the points in.

##### Description:

An array of Points from the curve.

##### Type:
Inherited from: Phaser.Curves.Curve#getPoints
Since: 3.0.0
Source: src/curves/Curve.js (Line 300)
getRandomPoint([out])

#### Description:

Get a random point from the curve.

#### Parameters:

name type arguments description
out Phaser.Math.Vector2 <optional>

A point object to store the result in.

The point.

##### Type:
Inherited from: Phaser.Curves.Curve#getRandomPoint
Since: 3.0.0
Source: src/curves/Curve.js (Line 349)
getResolution(divisions)

#### Description:

Get the resolution of the curve.

#### Parameters:

name type description
divisions number

Optional divisions value.

##### Description:

The curve resolution.

##### Type:
• number
Since: 3.0.0
getSpacedPoints([divisions], [stepRate], [out])

#### Description:

Get a sequence of equally spaced points (by arc distance) from the curve.

`1 + divisions` points will be returned.

#### Parameters:

name type arguments Default description
divisions number <optional> this.defaultDivisions

The number of divisions to make.

stepRate number <optional>

Step between points. Used to calculate the number of points to return when divisions is falsy. Ignored if divisions is positive.

out array | Array.<Phaser.Math.Vector2> <optional>

An optional array to store the points in.

##### Description:

An array of points.

##### Type:
Inherited from: Phaser.Curves.Curve#getSpacedPoints
Since: 3.0.0
Source: src/curves/Curve.js (Line 370)
getStartPoint([out])

#### Description:

Gets the starting point on the curve.

#### Parameters:

name type arguments description
out Phaser.Math.Vector2 <optional>

A Vector2 object to store the result in. If not given will be created.

##### Description:

The coordinates of the point on the curve. If an `out` object was given this will be returned.

##### Type:
Overrides: Phaser.Curves.Curve#getStartPoint
Since: 3.0.0
getTFromDistance(distance, [divisions])

#### Description:

Given a distance in pixels, get a t to find p.

#### Parameters:

name type arguments description
distance number

The distance, in pixels.

divisions number <optional>

Optional amount of divisions.

The distance.

##### Type:
• number
Inherited from: Phaser.Curves.Curve#getTFromDistance
Since: 3.0.0
Source: src/curves/Curve.js (Line 492)
getTangent(t, [out])

#### Description:

Get a unit vector tangent at a relative position on the curve. In case any sub curve does not implement its tangent derivation, 2 points a small delta apart will be used to find its gradient which seems to give a reasonable approximation

#### Parameters:

name type arguments description
t number

The relative position on the curve, [0..1].

out Phaser.Math.Vector2 <optional>

A vector to store the result in.

##### Description:

Vector approximating the tangent line at the point t (delta +/- 0.0001)

##### Type:
Inherited from: Phaser.Curves.Curve#getTangent
Since: 3.0.0
Source: src/curves/Curve.js (Line 430)
getTangentAt(u, [out])

#### Description:

Get a unit vector tangent at a relative position on the curve, by arc length.

#### Parameters:

name type arguments description
u number

The relative position on the curve, [0..1].

out Phaser.Math.Vector2 <optional>

A vector to store the result in.

##### Description:

The tangent vector.

##### Type:
Inherited from: Phaser.Curves.Curve#getTangentAt
Since: 3.0.0
Source: src/curves/Curve.js (Line 472)
getUtoTmapping(u, distance, [divisions])

#### Description:

Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant.

#### Parameters:

name type arguments description
u number

A float between 0 and 1.

distance number

The distance, in pixels.

divisions number <optional>

Optional amount of divisions.

##### Description:

The equidistant value.

##### Type:
• number
Inherited from: Phaser.Curves.Curve#getUtoTmapping
Since: 3.0.0
Source: src/curves/Curve.js (Line 513)
setClockwise(value)

#### Description:

Sets if this curve extends clockwise or anti-clockwise.

#### Parameters:

name type description
value boolean

The clockwise state of this curve.

##### Description:

This curve object.

##### Type:
Since: 3.0.0
setEndAngle(value)

#### Description:

Sets the end angle of this curve.

#### Parameters:

name type description
value number

The end angle of this curve, in radians.

##### Description:

This curve object.

Since: 3.0.0
setHeight(value)

#### Description:

Sets the height of this curve.

#### Parameters:

name type description
value number

The height of this curve.

##### Description:

This curve object.

##### Type:
Since: 3.0.0
setRotation(value)

#### Description:

Sets the rotation of this curve.

#### Parameters:

name type description
value number

The rotation of this curve, in radians.

##### Description:

This curve object.

##### Type:
Since: 3.0.0
setStartAngle(value)

#### Description:

Sets the start angle of this curve.

#### Parameters:

name type description
value number

The start angle of this curve, in radians.

##### Description:

This curve object.

Since: 3.0.0
setWidth(value)

#### Description:

Sets the width of this curve.

#### Parameters:

name type description
value number

The width of this curve.

##### Description:

This curve object.

Since: 3.0.0

#### Description:

Sets the horizontal radius of this curve.

#### Parameters:

name type description
value number

The horizontal radius of this curve.

##### Description:

This curve object.

Since: 3.0.0

#### Description:

Sets the vertical radius of this curve.

#### Parameters:

name type description
value number

The vertical radius of this curve.

##### Description:

This curve object.

Since: 3.0.0
toJSON()

#### Description:

JSON serialization of the curve.

##### Description:

The JSON object containing this curve data.

##### Type:
Since: 3.0.0
updateArcLengths()

#### Description:

Calculate and cache the arc lengths.

Inherited from: Phaser.Curves.Curve#updateArcLengths
Since: 3.0.0
Source: src/curves/Curve.js (Line 594)
<static> fromJSON(data)

#### Description:

Creates a curve from the provided Ellipse Curve Configuration object.

#### Parameters:

name type description
data Phaser.Types.Curves.JSONEllipseCurve

The JSON object containing this curve data.

##### Description:

The ellipse curve constructed from the configuration object.

Since: 3.0.0