ButtonSelector.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. cc.Class({
  2. extends: cc.Component,
  3. properties: {
  4. },
  5. onLoad() {
  6. this.node.on(cc.Node.EventType.TOUCH_START, () => {
  7. if (this.node.interactable) {
  8. this._setAllChildColor(this.node, new cc.Color(133, 133, 133, 255));
  9. }
  10. });
  11. this.node.on(cc.Node.EventType.TOUCH_END, () => {
  12. this._setAllChildColor(this.node, new cc.Color(255, 255, 255, 255));
  13. });
  14. this.node.on(cc.Node.EventType.TOUCH_CANCEL, () => {
  15. this._setAllChildColor(this.node, new cc.Color(255, 255, 255, 255));
  16. });
  17. },
  18. _setAllChildColor(node, color) {
  19. if (node && node.active) {
  20. if (node.childrenCount > 0) {
  21. for (var i = 0; i < node.children.length; i++) {
  22. this._setAllChildColor(node.children[i], color);
  23. }
  24. }
  25. node.color = color;
  26. }
  27. },
  28. onDestroy() {
  29. this.node.off(cc.Node.EventType.TOUCH_START, this);
  30. this.node.off(cc.Node.EventType.TOUCH_END, this);
  31. this.node.off(cc.Node.EventType.TOUCH_CANCEL, this);
  32. }
  33. });