class Paddle {
constructor(canvas, game) {
this.mouseX = this.x; ・・・1
this.addHandler();
}
addHandler() {
document.addEventListener('mousemove', e => {
this.mouseX = e.clientX; ・・・2
});
}
update(ball) {
const rect = this.canvas.getBoundingClientRect();
this.x = this.mouseX - rect.left - (this.w / 2); ・・・3
}
constructor でパドルの左上の位置(this.x)を変数 mouseX に代入しているaddHandler() でマウスが動いたら、マウスのブラウザでの位置(e.clientX)を変数 mouseX に代入しているupdate で this.x の位置を canvas でのパドル中央上の位置にしているとの認識ですが、this.x と this.mouseX と e.clientX の関係性と処理の流れが理解できていません。
ご教授願えないでしょうか。よろしくお願いします。
この回答を見るにはプレミアムプランへの登録が必要です
プレミアムプランとは?