ဂိုး အသံ
- 上一页 ဂိုး ပုံ
- 下一页 ဂိုး အယောက်
အဲ့ဒါက အသံကို အောက်ထိုးပါ။ ချိုင်းနက်များနှင့် နံပါတ်သုံး ပြီးနောက် ကြားနာတယ်လား။
အသံပေးခြင်း
HTML5 <audio> အဖွဲ့အသစ်ကို ကစားပွဲသို့ အသံနှင့် ဗိုင်းလုံးသံပေးပါ:
အောက်ပါ ဘာသာစကားများတွင် အသစ်အဖွဲ့အသစ်ကို ဖန်တီးရန် အက်ဥပဒါကို အသုံးပြုပါ:
အက်ဥပဒါ
function sound(src) { this.sound = document.createElement("audio"); this.sound.src = src; this.sound.setAttribute("preload", "auto"); this.sound.setAttribute("controls", "none"); this.sound.style.display = "none"; document.body.appendChild(this.sound); this.play = function(){ this.sound.play(); } this.stop = function(){ this.sound.pause(); } }
အသံအဖွဲ့အသစ်ကို ဖန်တီးရန် အသုံးပြုပါ: အသံ
ကြီးတည်ဆဲ အက်ဥပဒါကို အသုံးပြုရာ အကြီးကို အားနပ်သော ပျက်စီးနေသော အခွက်များကို အသံဖြင့် ပြောင်းလဲပေးပါ:
အက်ဥပဒါ
var myGamePiece; var myObstacles = []; var mySound; function startGame() { myGamePiece = new component(30, 30, "red", 10, 120); mySound = new sound("bounce.mp3"); myGameArea.start(); } function updateGameArea() { var x, height, gap, minHeight, maxHeight, minGap, maxGap; for (i = 0; i < myObstacles.length; i += 1) { if (myGamePiece.crashWith(myObstacles[i])) { mySound.play(); myGameArea.stop(); return; } } ... }
ဗိုင်းလုံးသံ
ဗိုင်းလုံးသံဖိုက်ကို ကစားပွဲမှာ ထပ်ပေးရန် အတိုင်းအရာ sound အဖွဲ့ကို ထပ်ထည့်ပြီး ကစားပွဲစတင်ချိန်တွင် ကယ်လွှမ်းခြုံထားပါ:
အက်ဥပဒါ
var myGamePiece; var myObstacles = []; var mySound; var myMusic; function startGame() { myGamePiece = new component(30, 30, "red", 10, 120); mySound = new sound("bounce.mp3"); myMusic = new sound("gametheme.mp3"); myMusic.play(); myGameArea.start(); }
- 上一页 ဂိုး ပုံ
- 下一页 ဂိုး အယောက်