this.ctx.beginPath() が必要なのはどういう場合ですか?

よく使われる fillRect() や strokeRect() では不要だったりします。
2021年1月10日
ユーザー

こんにちは。
this.ctx.beginPath()の記載方法について質問です。

Ballクラス内のdraw()メソッドでは、先頭にthis.ctx.beginPath()の記載があります。
draw() {
this.ctx.beginPath();
this.ctx.fillStyle = '#fdfdfd';
this.ctx.arc(this.x, this.y, this.r, 0, 2 * Math.PI);
this.ctx.fill();
}

しかし、Paddleクラス内のdraw()メソッドでは、記載がありません。
draw() {
this.ctx.fillStyle = '#fdfdfd';
this.ctx

Paddleクラスでは記載不要なのでしょうか?
使い分け等ありましたら教えて頂けると幸いです。

ご確認よろしくお願い致します。

この回答を見るにはプレミアムサービスへの登録が必要です

プレミアムサービスとは?