我有一个小游戏,当所有的心都失去时,应该会出现一个重置按钮。我一生都无法弄清楚为什么它没有出现。我重写了 3 次,想知道这是否是我分配其值的方式,但它们都不起作用。当我删除隐藏按钮的语句后,该按钮就会出现,但应该有验证语句在适当的位置,使其再次出现。
const resetButton = document.getElementById('reset');
function reset() {
location.reload();
}
resetButton.addEventListener('click', reset);
// Hide reset button until no hearts left
function hideReset() {
if (foodHeart1.src.match("images/emptyheart.png" && playHeart1.src.match("images/emptyheart.png"))) {
resetButton.style.display = "visible";
} else {
resetButton.style.display = "none";
}
}
hideReset();
我尝试过移动它,将其放置在新的区域,但运气不佳。我不知道还能怎么写这个。
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
什么调用函数 hideReset()?如果在主更新循环或命中碰撞中没有调用它,则没有任何东西可以到达那里。使用图像来查询玩家是否死亡是一个有趣的想法,但仅使用变量会更高效。
//way up at the top const resetButton = getElementById('reset'); resetButton.setAttribute('display', 'none'); //way up at the top //in the player class processDamage(hitVal){ this.HP -= hitVal; if(this.HP我觉得我可能需要添加更多代码才能完整回答......我希望这有帮助!