craftyjs.github.com

Crafty.polygon

Polygon object used for hitboxes and click maps. Must pass an Array for each point as an argument where index 0 is the x position and index 1 is the y position.

For example one point of a polygon will look like this: [0,5] where the x is 0 and the y is 5.

Can pass an array of the points or simply put each point as an argument.

When creating a polygon 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).

Example

new Crafty.polygon([50,0],[100,100],[0,100]);
new Crafty.polygon([[50,0],[100,100],[0,100]]);
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 poly = new Crafty.circle(0, 0, 10);
circle.shift(5,5);
//{x: 5, y: 5, radius: 10};