gets/sets the current width of the collider. For a circle collider it will always have the same width/height so updating one updates the other.
w
Examples
const circleExample = $.makeCircleCollider(
$.w/2, //x
$.h/2, //y
50 //diameter
);
circleExample.fill="blue";
const boxExample = $.makeBoxCollider(
$.w/2,
$.h/2,
150, //w
50 //h
);
circleExample.fill="orange";
function update() {
boxExample.w -= 1;
//a collider throws an error if its width is set to 0
if(boxExample.w <= 1) {
boxExample.w = 150;
}
boxExample.draw();
$.colour.fill="black";
$.text.print(
$.w/2,
$.h/2-10,
"box w"+boxExample.w.toString()
);
//when the w of a circle collider is changed the h is also updated, and vice versa.
circleExample.w += 1;
if(circleExample.w > $.w) {
circleExample.w = 25;
}
circleExample.draw();
$.colour.fill="black";
$.text.print(
$.w/2,
$.h/2+10,
"circle w"+circleExample.w.toString()
);
}