私のゲームには、キャラクタークラスがあります:
var NPC = function(isometry,timer,canvas,tile,tileMap,scrollPosition,
grid,spritesheet, r1, c1, currentHero, hh, hw,index) {
this.index = index;
....
NPC.prototype.w = new Worker('astar.js');
this.w.onmessage = function(e) {
//process worker results, 'index' is strongly needed
// e is data from worker
//it draws path for the character on the common tileMap:
tileMap[e.data[i].x][e.data[i].y] = index;
}
次に、メイン プログラムで、そのクラスの 2 つのオブジェクトを作成します。
var protagonist = new NPC(.....,0);
var char1 = new NPC(.....,10);
問題は、同じインデックス = 10 でパスを描画することです。
- 代わりに this.index を使用しますが、 this.w.onmessage で undefined になります
- 「NPC.prototype.w.onmessage = function(e) {」と呼びます - 同じ話
別の関数を宣言します。
NPC.prototype.wonmessage=function(e) {....}
this.w.onmessage = this.wonmessage();
Error: "e is undefined".
すべてのデータを関数に正しく送信するにはどうすればよいですか?