How do you center a rectangle in javaScript? Having the X and Y position of the rectangle being the center of the rectangle How do you center a rectangle in javaScript? Having the X and Y position of the rectangle being the center of the rectangle
How do you center a rectangle in javaScript? Having the X and Y position of the rectangle being the center of the rectangle. This is a rough idea for my code.
var cxt = canvas.getContext("2d");
var canvas = var canvas = document.getElementById("myCanvas");
function createSprite(x,y,width,height) {
this.x=x;
this.y=y;
this.width=width;
this.height=height;
this.display(){
cxt.beginPath();
cxt.rect(this.x,this.y,this.width,this.height);
cxt.fill();
cxt.stroke();
}
}
from Stackoverflow
Comments
Post a Comment