ButtonSafe.js 601 B

1234567891011121314151617181920212223
  1. cc.Class({
  2. extends: cc.Component,
  3. properties: {
  4. safeTime: {
  5. default: 0.5,
  6. tooltip: "按钮保护时间,指定间隔内只能点击一次."
  7. }
  8. },
  9. start:function(){
  10. var button = this.node.getComponent(cc.Button);
  11. if (!button) return;
  12. this.clickEvents = button.clickEvents;
  13. this.node.on('click', ()=>{
  14. button.clickEvents = [];
  15. this.scheduleOnce((dt)=>{
  16. button.clickEvents = this.clickEvents;
  17. }, this.safeTime);
  18. }, this);
  19. }
  20. });