0

Why won’t canvas.width and canvas.height work when used as object properties?

https://code.sololearn.com/WVZ7Xzvx5qCW/?ref=app It’s on lines 34 and 35 where I declare the ball’s x and y coordinates equal to the canvas.width/2 and canvas.height/2. The ball shows up, but it doesn’t appear in the middle of the canvas like it should. Why is this happening and what can I do to rectify this? Thanks.

9th Jan 2019, 4:53 AM
Thomas Czernek
Thomas Czernek - avatar
1 Respuesta
+ 4
Maybe it gets overwritten in ballmotion function, since you are not specifying Ypos. Try this: ballMotion(){ this.ballYPos = canvas.height/2 ; this.ballXPos = this.ballXPos + 1; if(this.ballXPos == canvas.width){ ++this.humanScore; } else if(this.ballXPos == 0){ ++this.computerScore; } }
9th Jan 2019, 11:00 PM
dρlυѕρlυѕ
dρlυѕρlυѕ - avatar