提示コードですが.p5ライブラリのrandom()
関数が呼び出せません。これはなぜでしょうか?他の関数は呼びさせるためライブラリのパスは通っています。
確認したこと
リファレンスを確認して関数名を確認
index.htmlを確認して読み込まれているかどうか確認
エラーコード
Uncaught ReferenceError: random is not defined at new Puyo (Game.js:77:27) at new Game (Game.js:112:21) at Main.js:3:14
参考サイト: https://qiita.com/bit0101/items/f4ca30e4c7ea289cb78e
リファレンス: https://p5js.org/reference/#/p5/random
html
1<!DOCTYPE html> 2<html lang=ja> 3 <head> 4 <meta charset="utf-8"> 5 <title>puyopuyo</title> 6 <body> 7//////////////////////////////////////////////////////////////////// 8 <script src=../p5/p5.js></script> 9//////////////////////////////////////////////////////////////////// 10 <!-- ユーティリティ --> 11 <script src=../Utility/Math.js></script> 12 <script src=../Utility/Vector.js></script> 13 <script src=../Utility/Collision.js></script> 14 15////////////////////////////////////////////////////////////////////////// 16 <!-- ゲームループ --> 17 <script src="Script/Game.js"></script> 18///////////////////////////////////////////////////////////////////////// 19 20 <script src=Script/Main.js></script> 21 22 </body> 23 24 </head> 25 26</html>
javascirpt
1 2// ################################################################ 3// # ぷよ クラス 4// ################################################################ 5class Puyo 6{ 7 8 getColor(rand) 9 { 10 if(rand == 0) 11 { 12 return fill(255,0,0); 13 } 14 else if(rand == 1) 15 { 16 return fill(0,255,0); 17 } 18 else if(rand == 2) 19 { 20 return fill(0,0,255); 21 } 22 else if(rand == 3) 23 { 24 return fill(255,255,0); 25 } 26 else if(rand == 4) 27 { 28 return fill(128,0,128); 29 } 30 31 32 } 33 34 constructor() 35 { 36/////////////////////////////////////////////////////////////////////////////////// 37 this.color = this.getColor(random(0,5)); //色 38////////////////////////////////////////////////////////////////////////////////// 39 this.position = new Vector(0,0); //座標 40 } 41 42 setPosition(pos) 43 { 44 this.position = pos; 45 } 46 47 48 49 Renderer() 50 { 51 fill(this.color); 52 noStroke(); 53 circle(this.position.x,this.position.y,CELL_SIZE); 54 55 } 56 57 58} 59 60 61
回答1件
あなたの回答
tips
プレビュー