【週刊ドットインストール】 256timesのクラスを準備中、Ruby/Ruby on Railsのロードマップページを追加
【週刊ドットインストール】 考える力を養うための新クラス『データで学ぶアルゴリズム』を256timesでリリース!
いつも丁寧なご回答ありがとうございます。 ■状況 returnを誤って drawGameoverメソッドに記入したためGAME OVERの画面が出ない状況になってしまいました。 -------------------------------------------------------------------------------- draw() { if(this.isGameOver) { this.drawGameover(); } this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height); this.ball.draw(); this.paddle.draw(); } drawGameover() { this.ctx.font = '28px "Arial Black'; this.ctx.fillStyle = 'tomato'; this.ctx.fillText('GAME OVER', 50, 150); return; //ここです } ---------------------------------------------------------------------------------------- ■質問 Gameクラスの下記1〜3に関してなぜretunが記入・不記入なのか詳細を教えてもらえますでしょうか。 1. update() { if (this.ball.getMissedStatus()) { this.isGameOver = true; //ここにreturn不記載理由 } 2. draw() { if(this.isGameOver) { this.drawGameover(); return; //ここにreturn記載理由 } 3.drawGameover() { this.ctx.font = '28px "Arial Black'; this.ctx.fillStyle = 'tomato'; this.ctx.fillText('GAME OVER', 50, 150); //ここにreturn不記載理由 } 以上、よろしくお願いいたします。
ドットインストールは、3分動画でマスターできるプログラミング学習サービスです。
3分で気軽に学習でき、スマートフォンからも視聴可能です。ホームページやWebサービスの制作を通して、実践的にプログラミングを学べます。
他にも、ゲーム制作やデータ分析・機械学習・AIに使われる言語まで幅広くカバー。学びたい分野のレッスンがきっと見つかります。
この回答を見るにはプレミアムプランへの登録が必要です
いつも丁寧なご回答ありがとうございます。
■状況
returnを誤って drawGameoverメソッドに記入したためGAME OVERの画面が出ない状況になってしまいました。
--------------------------------------------------------------------------------
draw() {
if(this.isGameOver) {
this.drawGameover();
}
this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
this.ball.draw();
this.paddle.draw();
}
drawGameover() {
this.ctx.font = '28px "Arial Black';
this.ctx.fillStyle = 'tomato';
this.ctx.fillText('GAME OVER', 50, 150);
return; //ここです
}
----------------------------------------------------------------------------------------
■質問
Gameクラスの下記1〜3に関してなぜretunが記入・不記入なのか詳細を教えてもらえますでしょうか。
1. update() {
if (this.ball.getMissedStatus()) {
this.isGameOver = true;
//ここにreturn不記載理由
}
2. draw() {
if(this.isGameOver) {
this.drawGameover();
return; //ここにreturn記載理由
}
3.drawGameover() {
this.ctx.font = '28px "Arial Black';
this.ctx.fillStyle = 'tomato';
this.ctx.fillText('GAME OVER', 50, 150);
//ここにreturn不記載理由
}
以上、よろしくお願いいたします。