Я пытаюсь получить некоторые кнопки для работы со звуком без успеха. Для страницы я использую Я его настроить так:с воспроизведением звука по клику
// javascript file for gun tutorial//
window.onload=function()
{
\t var extraAmmo = 210;
\t var maxAmmo = 30;
\t var currentAmmo = maxAmmo;
\t
\t var extraAmmoHud = document.getElementById("extra-ammo");
\t var currentAmmoHud = document.getElementById("current-ammo");
\t
\t var shootButton = document.getElementById("shoot-button");
\t var unloadButton = document.getElementById("unload-button");
\t var reloadButton = document.getElementById("reload-button");
\t \t refreshScreen();
\t \t
\t shootButton.onclick=function()
\t {
\t \t if(currentAmmo > 0)
\t \t {
\t \t \t currentAmmo--;
\t \t \t refreshScreen();
\t \t }
\t }
\t unloadButton.onclick=function()
\t {
\t if (currentAmmo > 0)
\t \t {
unloadTimer = setTimeout(unloadButton.onclick, 150)
\t currentAmmo--;
\t refreshScreen();
\t }
\t \t else unloadTimer = null;
\t }
\t reloadButton.onclick=function()
\t {
\t \t var difference = getDifference();
\t \t if(extraAmmo >= difference)
\t \t {
\t \t \t currentAmmo += difference;
\t \t \t extraAmmo -= difference;
\t \t }
\t \t else
\t \t {
\t \t \t currentAmmo += extraAmmo;
\t \t \t extraAmmo -= extraAmmo;
\t \t }
\t \t refreshScreen();
\t \t
\t \t function getDifference()
\t \t {
\t \t \t return maxAmmo -currentAmmo;
\t \t }
\t }
\t function refreshScreen()
\t {
\t \t extraAmmoHud.innerHTML="Extra Ammo: " + extraAmmo;
\t \t currentAmmoHud.innerHTML="Current Ammo: " + currentAmmo;
\t }
}
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Gun Tutorial</title>
<link rel="stylesheet" type="text/css" href="css/style.css"/>
<script src="js/gun.js"></script>
<audio src="sounds/GunShot.mp3"></audio>
<audio src="sounds/GunShotFullAuto.mp3"></audio>
<audio src="sounds/GunCockingFast.wav"></audio>
</head>
<body>
\t <div id="wrapper">
\t <header id="header">
\t \t <h1>Welcome to the Gun Show</h1>
\t </header>
\t <div id="content"></div>
\t <form>
\t <div id="boxobuttons">
\t \t <input type="button" value="Shoot" id="shoot-button" />
\t \t <input type="button" value="Unload" id="unload-button" />
\t \t <input type="button" value="Reload" id="reload-button" />
\t </div>
\t
\t \t <div id="ammo-count">
\t \t \t <p id="current-ammo"></p>
\t \t \t <p id="extra-ammo"></p>
\t \t </div>
\t </form>
\t <footer>
\t </footer>
\t </div>
</body>
</html>
Я пытаюсь увидеть, если мне нужно, чтобы звук выступать в качестве переменной, и каждая отдельная переменная может затем быть вставлены в разные переменные (shootButton, unloadButton и reloadButton), или мне нужно сделать что-то совершенно отдельное?
Спасибо за входной Томас, дайте мне время, и я вернусь с вами и сказать вам, если это работает. –
Похоже, что нет, на данный момент я хочу сказать, что я определил проблему, будучи, возможно, ей не нравятся звуковые файлы, находящиеся в ее собственной папке (звуки), поэтому я собираюсь переместить их в откройте index.html, чтобы узнать, работает ли это. –
перемещение его в открытое с index.html работало, теперь сделать то же самое для разгрузки и перезагрузки –