p5.CircleCollider
A Circle collision shape, used to detect overlap and displacement vectors with other collision shapes.
Table of Contents
- Methods
- Properties
- Static Methods
Constructor
p5.CircleCollider
-
center
-
radius
Parameters:
-
center
p5.Vector -
radius
Number
Methods
_computeScaledRadius
()
Call to update the cached scaled radius value.
_getCandidateAxes
-
other
Compute candidate separating axes relative to another object.
Parameters:
-
other
p5.CollisionShape
Returns:
_getMinRadius
-
axis
Get the shape's minimum radius on any axis for tunneling checks.
Parameters:
-
axis
p5.Vector
Returns:
_getRadiusOnAxis
()
Number
Get this shape's radius (half-width of its projection) along the given axis.
Returns:
_onTransformChanged
()
Recalculate cached properties, relevant vectors, etc. when at least one of the shape's transforms changes. The base CollisionShape (and PointCollider) only need to recompute the shape's center, but other shapes may need to override this method and do additional recomputation.
Compute the smallest movement needed to move this collision shape out of another collision shape. If the shapes are not overlapping, returns a zero vector to indicate that no displacement is necessary.
Parameters:
-
other
p5.CollisionShape
Returns:
draw
-
sketch
Debug-draw this collision shape.
Parameters:
-
sketch
P5instance to use for drawing
getBoundingBox
()
Top: number, bottom: number, left: number, right: number, width: number, height: number
Get world-space axis-aligned bounds information for this collision shape. Used primarily for the quadtree.
Returns:
}
overlap
-
other
Check whether this shape overlaps another.
Parameters:
-
other
p5.CollisionShape
Returns:
setParentTransform
-
parent
Overrides CollisionShape.setParentTransform Update this collider's parent transform, which will in turn adjust its position, rotation and scale in world-space and recompute cached values if necessary. If a Sprite is passed as the 'parent' then a new transform will be computed from the sprite's position/rotation/scale and used. Use the max of the x and y scales values so the circle encompasses the sprite.
Parameters:
-
parent
p5.Transform2D | Sprite
updateFromSprite
-
sprite
Update this collider based on the properties of a parent Sprite.
Parameters:
-
sprite
Sprite
Properties
_localTransform
p5.Transform2D
protected
Transform of this shape relative to its parent. If there is no parent, this is pretty much the world-space transform. This should stay consistent with _offset, _rotation and _scale properties.
_offset
p5.Vector
private
The center of the collision shape in local-space; also, the offset of the collision shape's center from its parent sprite's center.
_parentTransform
p5.Transform2D
protected
Transform of whatever parent object (probably a sprite) this shape is associated with. If this is a free-floating shape, the parent transform will remain an identity matrix.
_rotation
Number
private
Rotation in radians in local space (relative to parent). Note that this will only be meaningful for shapes that can rotate, i.e. Oriented Bounding Boxes
_scale
p5.Vector
private
Scale X and Y in local space. Note that this will only be meaningful for shapes that have dimensions (e.g. not for point colliders)
_scaledRadius
Number
private
Final radius of this circle after being scaled by parent and local transforms, cached so we don't recalculate it all the time.
center
p5.Vector
The center of the collision shape in world-space. Note: You can set this property with a value in world-space, but it will actually modify the collision shape's local transform.
getsDimensionsFromSprite
Boolean
If true, when calling updateFromSprite
this collider will adopt the
base dimensions of the sprite in addition to adopting its transform.
If false, only the transform (position/rotation/scale) will be adopted.
offset
p5.Vector
The center of the collision shape in local-space - if this collider is owned by a sprite, the offset of the collider center from the sprite center.
radius
Number
The unscaled radius of the circle collider.
rotation
Number
The local-space rotation of the collider, in radians.
Static Methods
Construct a new CircleCollider with given offset for the given sprite.