ButtonSelector.js 1.1 KB

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