ဂိမ်းအသံ
အသံအတိုးအကျယ်ကိုဖွင့်ပါ။ အနီရောင်စတုရန်းအတားအဆီးတစ်ခုနှင့်တွေ့သောအခါ "dunk" ကိုသင်ကြားပါသလား။
အသံထည့်နည်း။
သင့်ဂိမ်းများသို့ အသံနှင့် တေးဂီတများထည့်ရန် 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();
}
}
အသံအရာဝတ္ထုအသစ်တစ်ခုကို ဖန်တီးရန်အတွက် တည်ဆောက်သူအား အသုံးပြုပြီး sound
အနီရောင်စတုရန်းအား အတားအဆီးတစ်ခုနှင့် ထိမိသောအခါ၊ အသံကိုဖွင့်ပါ-
ဥပမာ
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;
}
}
...
}
နောက်ခံဂီတ
သင့်ဂိမ်းတွင် နောက်ခံတေးဂီတကို ထည့်သွင်းရန်၊ အသံအရာဝတ္ထုအသစ်တစ်ခုကို ပေါင်းထည့်ကာ ဂိမ်းကိုစသောအခါတွင် စတင်ကစားပါ-
ဥပမာ
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();
}