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

Popular posts from this blog

How to extract items from a subarray and push them to the main array

Detox gets stuck on JS Timer/Main Run Loop when registering a lot of screens with React Native Navigation Detox gets stuck on JS Timer/Main Run Loop when registering a lot of screens with React Native Navigation

\\u0000 cannot be converted to text error \\u0000 cannot be converted to text error