사용 후 나는이 같은 세 개의 버튼이 있습니다사용 안 함을 클릭 phaser.io에서 한 번의 클릭 자바 스크립트
astroid: function() {
astroid1 = this.add.button(15, 80, 'astroid1', this.astroid1Clicked, this);
astroid2 = this.add.button(200, 10, 'astroid2', this.astroid2Clicked, this);
astroid3 = this.add.button(400, 40, 'astroid3', this.astroid3Clicked, this);
astroid4 = this.add.button(622, 90, 'astroid4', this.astroid4Clicked, this);
},
을 모든 버튼에 대한 기능을 가지고는 클릭 :
// Observing which asteroid is clicked and checking answer accordingly.
astroid1Clicked: function() {
this.fire();
//console.log(astroidContains[0]);
// console.log(answear);
//this.isCorrectAnswerHit(25, 100);
if (astroidContains[0] == answear) {
setTimeout(function() {
//50 and 100 are the axis of astroid1
Game.isCorrectAnswerHit(50, 100);
}, 500);
} else {
this.isWrongAnswerHit();
}
allowClick = false;
return false;
},
astroid2Clicked: function() {
this.fire();
//console.log(astroidContains[1]);
//console.log(answear);
if (astroidContains[1] == answear) {
setTimeout(function() {
Game.isCorrectAnswerHit(260, 10);
}, 500);
} else {
this.isWrongAnswerHit();
}
allowClick = false;
return false;
},
astroid3Clicked: function() {
this.fire();
//console.log(astroidContains[2]);
//console.log(answear);
if (astroidContains[2] == answear) {
setTimeout(function() {
Game.isCorrectAnswerHit(450, 40);
}, 500);
} else {
this.isWrongAnswerHit();
}
allowClick = false;
return false;
},
astroid4Clicked: function() {
this.fire();
//bullets.destroy();
//console.log(astroidContains[3]);
//console.log(answear);
if (astroidContains[3] == answear) {
setTimeout(function() {
Game.isCorrectAnswerHit(620, 100);
}, 500);
} else {
this.isWrongAnswerHit();
}
allowClick = false;
return false;
},
내가 하나에 사용자가 클릭으로 원하는 버튼은 사용자가 클릭하는 버튼을 포함하여 모든 버튼이 비활성화 될 때 모든 기능이 실행되고 사용자는 아무 버튼이나 클릭 할 수 있습니다. 많은 것을 시도했지만 그들이 원하는대로 작동하지 않도록 도와주세요. jQuery가 없으면됩니다.
먼저 코드를 리팩터링해야한다고 생각합니다. 반복되는 내용이 많습니다. 예를 들어, 대답 확인 논리를 매개 변수로 필요한 정보를 전달하는 별도의 함수로 옮길 수 있습니다. –
모든 버튼을 클릭 할 때마다 다른 작업을 수행하기 때문에 작업이 완료 될 때까지 코드를 반복하고 있습니다. 다른 또는 동일한 버튼 클릭을 방지하고 싶습니다. –