-4
現在、コードは1秒間に60回(setInterval)の箇条書きを作成しています 私はループを試しましたが、まったく動作しませんでした。 火災発生率をどのように調整することができますか?キャンバスゲーム|どのように火災の速度を制御する?
ありがとうございました。
現在、コードは1秒間に60回(setInterval)の箇条書きを作成しています 私はループを試しましたが、まったく動作しませんでした。 火災発生率をどのように調整することができますか?キャンバスゲーム|どのように火災の速度を制御する?
ありがとうございました。
ほとんどのリアルタイムゲームでは、アニメーションを制御するメインループがあります。あなたはこれに火のコントロールを追加します。
// object to hold details about the gun
const gun = {
fireRate : 2, // in frames (if 60 frames a second 2 would be 30 times a second
nextShotIn : 0, // count down timer till next shot
update() { // call every frame
if(this.nextShotIn > 0){
this.nextShotIn -= 1;
}
},
fire(){
if(this.nextShotIn === 0){
// call function to fire a bullet
this.nextShotIn = this.fireRate; // set the countdown timer
}
}
}
function mainAnimationLoop()
// game code
gun.update();
if(fireButtonDown){
gun.fire(); // fire the gun. Will only fire at the max rate you set with fireRate
}
// rest of game code
}
ありがとう!それは完全にうまくいく! – Eden
ようこそ![so]!このサイトでは、自分でコードを書くことができます**。 ** [もっと研究をして](// meta.stackoverflow.com/questions/261592)**あなたが問題を抱えていると、あなたが試みたものを投稿することができます** (** stackoverflow.com/help/mcve)を提供しています。私は良い質問と[完璧な質問]を読むことをお勧めします(http://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/)。また、[ツアー]を取って** [this](// meta.stackoverflow.com/questions/347937/)**を必ず読んでください。 –
コードなしで低品質の質問を既に[尋ねました](http://stackoverflow.com/questions/43760692/html5-canvas-game-how-to-make-players-shoot) –
@AlonEitanこのような疑問を生み出すものは、これほど多くの票を得て、このような質問は閉じられますが、http://stackoverflow.com/q/2142535/3877726は保護されますか?私に縫い目は、それは良い質問をするドローの運のちょうど運。 – Blindman67