●やりたい事
drawImagを配列に入れたい
●状況
画像はcanvasに描かれているのですが、配列に情報が入ってないです。
デベロッパーツールで確認すると配列が無いとされて処理が進んでいきます。
どこが間違っているかヒントをいただけないでしょうか?
考え方がおかしい等、指摘をいただけるとなおありがたいです。
</script>for(let i = 0 ; i < imageUrls.length; i++){//配列を回してimage要素を生成,実行 images[i] = document.createElement("img") images[i].src = imageUrls[i] images[i].onload = () =>{ if(i == 0 ) makeMap(mapd,images[i]) else if (i == 2) startChara(mapd,images[i],0,32,32,1010,1960,32,32) else return; } } } //MAPimageを繋ぐ mapCell配列にrow配列を入れる function makeMap(mapd,image){ const width = 40; const height = 40; let row = new Array();//処理用 let mapCell = new Array();//本体 map[recode[x]] let imageData; for(let field = 0; field < width; field ++){ row = new Array();//行の配列 for(cel = 0; cel < height; cel ++){ sxI = random(7)*100 row[cel] = imageMake(mapd,image,sxI,100,100,cel*50,field*50,50,50) } mapCell.push(row) } return mapCell } //image生成 function imageMake(mapd,image,sxI,sw,sh,dxI,dyI,dw,dh){ let imagePath = mapd.drawImage(image,sxI,0,sw,sh,dxI,dyI,dw,dh) return imagePath } //キャラクターの初期位置 function startChara(mapd,image,sxI,sw,sh,dxI,dyI,dw,dh){ let chara = imageMake(mapd,image,sxI,sw,sh,dxI,dyI,dw,dh) return chara } //乱数 function random(int){ let i = Math.floor(Math.random()*int) return i }
単にmakeMap()の返り値を受け取っていないように見えますが……。
あと表記が崩れて見難いので、編集で直してください。
回答1件
あなたの回答
tips
プレビュー