現在、リセットコードを作成しようとしています。プレイヤーが敵と衝突したときに、svgからすべてのコレクティブ(ペレットと呼んでいます)をクリアしてから私はループを持っています。何らかの理由で、ペレット以外のすべてのペレットをクリアしています。何らかの理由でペレットが作られているように、ペレットを作り直すこともありません。 svg変数はスコア、プレーヤー、ゴースト(敵)、ペレットです。 ループが動作していない複数の子どもをクリアする
この
はリセットコードです:function destroyPlayer()
{
alert("Game Over");
score = 0;
scoreElement.textContent = 'score: ' + score;
pelletCount=0;
constantCount = 1;
//need code to take out all pellets from svg
for(i = 0; i < 100; i++)
{
if(svg.children[i].id != "ghost" &&
svg.children[i].id != "score" &&
svg.children[i].id != "player")
{
svg.removeChild(svg.children[i]);
}
}
positionPellet();
positionGhost();
}
そして、これはペレットをリメイクコードです:(位置ペレット法)
function positionPellet()
{
while(pelletCount < constantCount*3)
{
var pellet = document.createElementNS(xmlns, 'circle');
pellet.setAttribute('cx', Math.random() * 900);
pellet.setAttribute('cy', Math.random() * 400);
pellet.setAttribute('r' , 10);
pellet.className.baseVal = "pelClass";
pelletCount++;
svg.appendChild(pellet);
}
}