Crafty.circle Class

Circle object used for hitboxes and click maps. Must pass a x, a y and a radius value.

Example

var centerX = 5,
    centerY = 10,
    radius = 25;

new Crafty.circle(centerX, centerY, radius);

When creating a circle for an entity, each point should be offset or relative from the entities x and y (don't include the absolute values as it will automatically calculate this).

Methods

Back to top

.containsPoint()

public Boolean .containsPoint(Number x, Number y)
x

X position of the point

y

Y position of the point

Method is used to determine if a given point is contained by the circle.

Example

var circle = new Crafty.circle(0, 0, 10);
circle.containsPoint(0, 0); //TRUE
circle.containsPoint(50, 50); //FALSE
Back to top

.shift()

public void .shift(Number x, Number y)
x

Amount to shift the x axis

y

Amount to shift the y axis

Shifts the circle by the specified amount.

Example

var circle = new Crafty.circle(0, 0, 10);
circle.shift(5,5);
//{x: 5, y: 5, radius: 10};