I'm trying to build brick-breaker game, however, the paddle does not show up. Seems like this.position.x, this.position.y, this.width, this.height
is undefined..does anyone know why?? please help
let canvas=document.querySelector('.canvas')
let ctx=canvas.getContext('2d')
const gameWidth=800;
const gameHeight=500;
// ctx.clearRect(0, 0, 800, 500)
/////////////paddle class//////////
class Paddle{
constructor(gameWidth, gameHeight){
this.width=150;
this.height=30;
this.position={
x:gameWidth/2-this.width/2,
y:gameHeight-this.height-10
};
}
draw(ctx){
ctx.fillStyle='#32a852'
ctx.fillRect(this.position.x, this.position.y, this.width, this.height)
}
}
//////////controller///////
let paddle=new Paddle(gameWidth,gameHeight);
paddle.draw(ctx);///not working
ctx.fillRect(10,10,10,10)//this working