我有三个这样的按钮:
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。
最佳答案
为什么不使用已有的标志?
astroid4Clicked: function() {
if (this.allowClick == true) {
effect...
this.allowClick = false;
}
}
然后您只需决定何时以及在什么情况下将标志恢复为 true。
最好检查 update() 函数中的标志,而不是在每个函数中单独检查。
是的,你有很多重复的代码......
关于javascript - 使用 JavaScript 在 Phaser.io 中单击一次后禁用单击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38736944/