gpt4 book ai didi

javascript:我的声音只播放一次?

转载 作者:太空宇宙 更新时间:2023-11-04 14:25:10 24 4
gpt4 key购买 nike

我为我的游戏制作了一项名为 Blitz 的技能。它的功能是在 6 秒内攻击对手 3 次。

我在技能中添加了声音文件,这样你就可以听到你所做的事情的提示,这样你就不必阅读文本日志了。但我遇到的问题是,当我击中对手 2 次或更多次时,声音文件只播放一次,而不是两次。

例如:这有效 - 命中,未命中,命中。例如:这不起作用 - Hit,Hit(无声音),Miss(声音)

为什么会跳过或不播放?

// BLITZ SKILL 

document.getElementById("blitz").addEventListener('click', function() {
atbReset();
DB();
RET();
window.setTimeout(function() { blitzskill() }, 1000);
window.setTimeout(function() { blitzskill() }, 2000);
window.setTimeout(function() { blitzskill() }, 3000);
});

function blitzskill(){
var criticalRoll = Math.floor(Math.random() * 100 + 1);
var precisionRoll = Math.floor(Math.random() * cs.precision + 1);
var npcParryRoll = Math.floor(Math.random() * ds.parry + 1);
var damage = Math.floor(Math.random() * cs.strength * 1);

if (character.energy <= 4) {
addMessage("Not enough energy!")
return;
}
if (precisionRoll < npcParryRoll) {
addMessage("The Dragon evaded your attack!");
character.energy -= 5;
miss.play(); // PLAY MISS SOUND
}
else if (damage - ds.armor <= 0) {
character.energy -= 5;
addMessage("Your opponents armor withstood your attack!");
armor.play(); // PLAY MISS/ARMOR SOUND
}
else if (cs.critical >= criticalRoll) {
damage *= 2;
damage -= ds.armor;
dragon.hp -= damage;
character.energy -= 5;
document.getElementById("npchp").innerHTML = dragon.hp;
addMessage("Critical Strike! Dragon suffers " + damage + " hp!")
swoosh.play(); // PLAY HIT SOUND
}
else {
dragon.hp -= damage;
damage -= ds.armor;
document.getElementById("npchp").innerHTML = dragon.hp;
addMessage("You hit the dragon for " + damage + " hp!");
character.energy -= 5;
swoosh.play(); // PLAY HIT SOUND
}
document.getElementById("energy").innerHTML = character.energy;
};

最佳答案

试试这个:

swoosh.pause();// ensure sound is not already playing 
swoosh.currentTime = 0; //reset time
swoosh.play(); // PLAY HIT SOUND

我所做的只是添加逻辑以确保您在声音开始时调用播放

关于javascript:我的声音只播放一次?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19613081/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com