提示コードですがコメント部///のコードですがなぜエラーになるのでしょか?以下のError提示コード部です。参考サイトと同じようにコードを作ったのですがエラーになります。これは何が原因なのでしょうか?
参考サイト: https://www.tohoho-web.com/js/class.htm
Error
1Game.js:49 Uncaught RangeError: Maximum call stack size exceeded 2 at Player.get position [as position] (Game.js:49) 3 at Player.get position [as position] (Game.js:49) 4 at Player.get position [as position] (Game.js:49) 5 at Player.get position [as position] (Game.js:49) 6 at Player.get position [as position] (Game.js:49) 7 at Player.get position [as position] (Game.js:49) 8 at Player.get position [as position] (Game.js:49) 9 at Player.get position [as position] (Game.js:49) 10 at Player.get position [as position] (Game.js:49) 11 at Player.get position [as position] (Game.js:49) 12get position @ Game.js:49 13get position @ Game.js:49 14get position @ Game.js:49 15省略 16get position @ Game.js:49 17get position @ Game.js:49 18get position @ Game.js:49 19get position @ Game.js:49 20 21Show 170 more frames 22Main.js:19 Uncaught ReferenceError: Cannot access 'entry' before initialization 23 at draw (Main.js:19) 24 at p5._main.default.redraw (p5.js:70809) 25 at _draw (p5.js:63046)
js
1 2class Enemy 3{ 4 constructor(pos) 5 { 6 this.position = new Vector(pos.x,pos.y); 7 this.alive = true; 8 this.size = 50; 9 } 10 11 Init(pos) 12 { 13 this.position = new Vector(pos.x,pos.y); 14 this.alive = true; 15 16 } 17 18 Update() 19 { 20 21 } 22 23 Renderer() 24 { 25 //fill(color(0,100,0)); 26 line(this.position.x,this.position.y,this.position.x + this.size,this.position.y + this.size); 27// triangle(this.position.x,this.position.y + this.size, 28 // this.position.x - this.size,this.position.y - this.size, 29 // this.position.x + this.size,this.position.y - this.size); 30 31 } 32 33} 34 35 36class Player 37{ 38 constructor() 39 { 40 this.acce = new Vector(0,0); //sin波 41 this.position = new Vector(300,300); 42 this.acce = new Vector(0,0); 43 this.alive = true; 44 this.size = 100; 45 } 46//////////////////////////////////////////////////////////////// 47 get position() 48 { 49 return this.position; 50 } 51//////////////////////////////////////////////////////////////// 52 set position(p) 53 { 54 this.position.x = p.x; 55 this.position.y = p.y; 56 57 } 58 59 60 Update() 61 { 62 KeyInput(this.position,this.acce); 63 } 64 65 66 Renderer() 67 { 68 line(this.position.x,this.position.y,this.position.x + this.size,this.position.y + this.size); 69 70 } 71 72} 73 74class Bullet 75{ 76 77} 78 79 80class Game 81{ 82 83 //オブジェクトプール 84 EnemyInstance(pos) 85 { 86 this.enemy.forEach(item => 87 { 88 89 if(item.alive === false) 90 { 91 item.Init(pos); 92 return; 93 } 94 95 96 }); 97 98 this.enemy.push(new Enemy(new Vector(pos.x,pos.y))); 99 return; 100 } 101 102 constructor() 103 { 104 105 this.enemy = new Array(); //Enemy 配列 106 this.Player = new Player(); //Player 107 108 for(let i = 0; i< 10; i++) 109 { 110 this.EnemyInstance(new Vector(100 + 40 * i,100)); 111 } 112 113 114 } 115 116 117 Collision(posA,posB) 118 { 119 if(Collision.LineSegment(posA,posB) == true) 120 { 121 return true; 122 } 123 else 124 { 125 return false; 126 } 127 } 128 129 Update() 130 { 131 this.enemy.forEach(item => 132 { 133 item.Update(); 134 if((this.Collision(this.player.position,item.position) === true) && (item.alive === true)) 135 { 136 item.alive = false; 137 } 138 139 }); 140 141 142 143 144 } 145 146 147 Renderer() 148 { 149 this.enemy.forEach( item => item.Renderer()); 150 this.plyer.Renderer(); 151 } 152 153 154 155 156 157 158}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2021/09/18 13:25
2021/09/18 16:21