Class: Circle
shapes/circle.Circle
Represents a circle in 2D space with a radius and centre.
Hierarchy
โณ
Circle
โณโณ
CircleCollider
Constructors
constructor
โข new Circle(radius
, centre?
, rotation?
)
Creates a new Circle instance with a radius, position and rotation.
Parameters
Name | Type | Description |
---|---|---|
radius | number | The radius of the circle |
centre? | vec2 | The circle's centre in world space, default is [0, 0] |
rotation? | number | The circle's rotation, default is 0. |
Overrides
Defined in
src/shapes/circle.ts:32
Properties
listeners
โข Protected
listeners: Object
= {}
Index signature
โช [index: string
]: Listener
[]
Inherited from
Defined in
src/object2d.ts:32
opacity
โข opacity: number
= 1
Opacity of the shape.
This is an opacity of the whole shape which is applied to the shape's entire texture equally.
Range is 0 (completely transparent) to 1 (completely opaque)
Inherited from
Defined in
src/shapes/shape.ts:28
radius
โข Private
radius: number
Defined in
src/shapes/circle.ts:23
texture
โข texture: Texture
= defaultTexture
Inherited from
Defined in
src/shapes/shape.ts:19
Methods
addEventListener
โธ addEventListener(event
, listener
): boolean
Executes a function when an event is fired.
Parameters
Name | Type | Description |
---|---|---|
event | string | The event to listen for |
listener | Listener | The function to execute when the event fired |
Returns
boolean
Wether or not the listener was added
Inherited from
Defined in
src/object2d.ts:209
fireEvent
โธ fireEvent(event
, ...e
): void
Executes all listeners attached to a given event.
Parameters
Name | Type | Description |
---|---|---|
event | string | The event to fire |
...e | any | The data to pass to each event listener |
Returns
void
Inherited from
Defined in
src/object2d.ts:185
getBaseVertices
โธ getBaseVertices(): vec2
[]
Calculates the base vertices of the circle.
These vertices are the base vertices for a quad, scaled to the diameter of the Circle instance.
Returns
vec2
[]
The circle's base vertices
Overrides
Defined in
src/shapes/circle.ts:81
getEventListeners
โธ getEventListeners(event
): Listener
[]
Gets the listeners attached to an event.
Parameters
Name | Type |
---|---|
event | string |
Returns
Listener
[]
An array of listeners attached to the given event
Inherited from
Defined in
src/object2d.ts:198
getEvents
โธ getEvents(): string
[]
Gets the events that can be listened to on the object.
Returns
string
[]
The events the object supports
Inherited from
Defined in
src/object2d.ts:175
getIndices
โธ getIndices(offset?
): Uint16Array
Gets the circle's vertex indices for drawing using element arrays.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
offset | number | 0 | An offset to apply to each index |
Returns
Uint16Array
The circle's vertex indices with the given offset added to each index
Overrides
Defined in
src/shapes/circle.ts:107
getPoints
โธ getPoints(): vec2
[]
Calculates the bounding points of the Shape instance.
NOTE: The shape's vertices are recalculated every time this function is called.
Returns
vec2
[]
The bounding points of the box
Inherited from
Defined in
src/shapes/shape.ts:136
getPosition
โธ getPosition(): vec2
Gets the object's position.
Returns
vec2
The object's position as a vec2
Inherited from
Defined in
src/object2d.ts:82
getRadius
โธ getRadius(): number
Gets the radius of the circle.
Returns
number
The radius of the circle
Defined in
src/shapes/circle.ts:149
getRotation
โธ getRotation(): number
Gets the object's rotation as a number in radians relative to y+.
Returns
number
The object's rotation
Inherited from
Defined in
src/object2d.ts:139
getUVCoords
โธ getUVCoords(): Float32Array
Calculates the circle's UV coords to be used for texture rendering.
Returns
Float32Array
the circle's UV coords
Overrides
Defined in
src/shapes/circle.ts:116
getVertices
โธ getVertices(): number
[]
Calculates the shape's vertices in local space.
Returns
number
[]
The shape's vertices
Inherited from
Defined in
src/shapes/shape.ts:57
getVerticesClipSpace
โธ getVerticesClipSpace(origin
, scale
, rotation?
, camera?
): number
[]
Calculates the shape's vertices relative to the provided origin in world space.
Parameters
Name | Type | Description |
---|---|---|
origin | vec2 | The origin to calculate the vertices relative to, should be a world position |
scale | vec2 | The vector to scale the world space vertices by to obtain clip space values |
rotation? | number | An optional rotation to apply to the vertices |
camera? | Camera | An optional camera to get vertices relative to |
Returns
number
[]
The shape's vertices relative to the provided origin in clip space
Inherited from
Defined in
src/shapes/shape.ts:87
getVerticesWorld
โธ getVerticesWorld(origin
, rotation?
, returnVecs?
): number
[] | vec2
[]
Calculates the circle's vertices relative to the provided origin in world space.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
origin | vec2 | undefined | The origin to calculate the vertices relative to, should be a world position |
rotation? | number | undefined | An optional world space rotation to apply to the vertices |
returnVecs | boolean | false | Wether or not to return the vertices as vec2s or raw numbers |
Returns
number
[] | vec2
[]
The circle's vertices relative to the provided origin in world space
Overrides
Defined in
src/shapes/circle.ts:48
moveRight
โธ moveRight(dist
): void
Moves the object's position right (x+) relative to it's rotation.
Parameters
Name | Type | Description |
---|---|---|
dist | number | The distance to move right, can be + or - |
Returns
void
Inherited from
Defined in
src/object2d.ts:100
moveUp
โธ moveUp(dist
): void
Moves the object's position up (y+) relative to it's rotation.
Parameters
Name | Type | Description |
---|---|---|
dist | number | The distance to move up, can be + or - |
Returns
void
Inherited from
Defined in
src/object2d.ts:114
removeEventListener
โธ removeEventListener(event
, listener
): boolean
Removes a listener from an event.
Parameters
Name | Type | Description |
---|---|---|
event | string | The event the listener is attached to |
listener | Listener | The listener to remove |
Returns
boolean
Wether or not the listener was removed
Inherited from
Defined in
src/object2d.ts:223
render
โธ render(position?
, rotation?
, zIndex?
): void
Renders the shape using the Renderer.
Parameters
Name | Type | Description |
---|---|---|
position? | vec2 | The x and y position to render the shape at |
rotation? | number | The rotation to apply to the rendered shape |
zIndex? | number | The z position of the rendered shape |
Returns
void
Inherited from
Defined in
src/shapes/shape.ts:41
rotate
โธ rotate(angle
): void
Increments the object's rotation by an angle in radians.
Parameters
Name | Type | Description |
---|---|---|
angle | number | The angle to rotate by in radians |
Returns
void
Inherited from
Defined in
src/object2d.ts:148
setPosition
โธ setPosition(pos
): void
Sets the object's position.
Parameters
Name | Type | Description |
---|---|---|
pos | vec2 | The object's new position |
Returns
void
Inherited from
Defined in
src/object2d.ts:43
setPositionX
โธ setPositionX(x
): void
Sets the x component of the object's position.
Parameters
Name | Type | Description |
---|---|---|
x | number | The object's new x coordinate |
Returns
void
Inherited from
Defined in
src/object2d.ts:56
setPositionY
โธ setPositionY(y
): void
Sets the y component of the object's position.
Parameters
Name | Type | Description |
---|---|---|
y | number | The object's new y coordinate |
Returns
void
Inherited from
Defined in
src/object2d.ts:69
setRadius
โธ setRadius(radius
): void
Sets the circle's radius.
throws
When the provided radius is < 0
Parameters
Name | Type | Description |
---|---|---|
radius | number | The circle's new radius |
Returns
void
Defined in
src/shapes/circle.ts:138
setRotation
โธ setRotation(angle
): void
Sets the object's rotation.
Parameters
Name | Type | Description |
---|---|---|
angle | number | The object's new rotation |
Returns
void
Inherited from
Defined in
src/object2d.ts:128
setupEvents
โธ Protected
setupEvents(): void
Sets all the events that can be used in listeners
.
Listeners can be added for an event using:
this.listeners.eventName = [];
example
Setup listeners for "position" and "rotate" events.
this.listeners.position = [];
this.listeners.rotate = [];
Returns
void
Inherited from
Defined in
src/object2d.ts:165
translate
โธ translate(v
): void
Translates the object by the provided vector.
Parameters
Name | Type | Description |
---|---|---|
v | vec2 | The vector to translate by |
Returns
void
Inherited from
Defined in
src/object2d.ts:91
vertexScale
โธ Private
vertexScale(v1
, v2
): vec2
Scales the first vector by the components in the second vector, returning the resultant vector.
Parameters
Name | Type | Description |
---|---|---|
v1 | vec2 | The first vector |
v2 | vec2 | The second vector |
Returns
vec2
A new vector with the scaled components
Defined in
src/shapes/circle.ts:127