ဂိမ်းလှုပ်ရှားမှု
Game Rotation အခန်းတွင် ရှင်းပြထားသည့် အစိတ်အပိုင်းများကို ပုံဆွဲနည်းအသစ်ဖြင့်၊ ရွေ့လျားမှုများသည် ပိုမိုပျော့ပြောင်းပါသည်။
အရာဝတ္ထုတွေကို ဘယ်လိုရွှေ့မလဲ။
အစိတ်အပိုင်း၏ လက်ရှိအမြန်နှုန်းကို ကိုယ်စားပြုသည့် တည်ဆောက်သူ speed
သို့ ပိုင်ဆိုင်မှု တစ်ခု ထည့်ပါ ။component
နှင့် . newPos()
တို့ကို အခြေခံ၍ အစိတ်အပိုင်း၏ အနေအထားကို တွက်ချက်ရန် နည်းလမ်း တွင် အပြောင်းအလဲအချို့ ပြုလုပ်ပါ ။speed
angle
ပုံသေအားဖြင့်၊ အစိတ်အပိုင်းများသည် အပေါ်သို့ မျက်နှာမူနေပြီး၊ speed property ကို 1 သို့ သတ်မှတ်ခြင်းဖြင့်၊ အစိတ်အပိုင်းသည် ရှေ့သို့ စတင်သွားပါမည်။
ဥပမာ
function component(width, height, color, x, y) {
this.gamearea = gamearea;
this.width = width;
this.height = height;
this.angle = 0;
this.speed = 1;
this.x = x;
this.y = y;
this.update = function() {
ctx = myGameArea.context;
ctx.save();
ctx.translate(this.x, this.y);
ctx.rotate(this.angle);
ctx.fillStyle = color;
ctx.fillRect(this.width / -2, this.height / -2, this.width, this.height);
ctx.restore();
}
this.newPos = function() {
this.x += this.speed * Math.sin(this.angle);
this.y -= this.speed * Math.cos(this.angle);
}
}
အကွေ့များ ပြုလုပ်ခြင်း။
ဘယ်ညာ အလှည့်အပြောင်းလည်း လုပ်ချင်တယ်။ moveAngle
လက်ရှိရွေ့လျားနေသောတန်ဖိုး သို့မဟုတ် လှည့်ခြင်းထောင့်ကို ညွှန်ပြသည့် ဟုခေါ်သော ပစ္စည်းအသစ်တစ်ခု ပြုလုပ် ပါ။ ပိုင်ဆိုင်မှုအပေါ် အခြေခံ၍ newPos()
တွက်ချက်နည်းတွင်
၊angle
moveAngle
ဥပမာ
မရွှေ့မပြောင်းနိုင်သော ပိုင်ဆိုင်မှုကို 1 ဟု သတ်မှတ်ပြီး ဘာဖြစ်မည်ကို ကြည့်ပါ-
function component(width, height, color, x, y) {
this.width = width;
this.height = height;
this.angle = 0;
this.moveAngle = 1;
this.speed = 1;
this.x = x;
this.y = y;
this.update = function() {
ctx = myGameArea.context;
ctx.save();
ctx.translate(this.x, this.y);
ctx.rotate(this.angle);
ctx.fillStyle = color;
ctx.fillRect(this.width / -2, this.height / -2, this.width, this.height);
ctx.restore();
}
this.newPos = function() {
this.angle += this.moveAngle * Math.PI / 180;
this.x += this.speed * Math.sin(this.angle);
this.y -= this.speed * Math.cos(this.angle);
}
}
Keyboard ကိုသုံးပါ။
ကီးဘုတ်အသုံးပြုသောအခါ အနီရောင်စတုရန်းပုံသည် မည်သို့ရွေ့လျားသနည်း။ အပေါ်နှင့်အောက် ရွှေ့ပြီး ဘေးမှတစ်ဖက်သို့ ရွှေ့မည့်အစား သင် "တက်" မြှားကို အသုံးပြုသောအခါ အနီရောင်စတုရန်းကို ရှေ့သို့ရွှေ့ကာ ဘယ်ညာ မြှားများကို နှိပ်သည့်အခါ ဘယ်ညာ လှည့်ပါ။