CircleMode.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Learn cc.Class:
  2. // - [Chinese] http://www.cocos.com/docs/creator/scripting/class.html
  3. // - [English] http://www.cocos2d-x.org/docs/editors_and_tools/creator-chapters/scripting/class/index.html
  4. // Learn Attribute:
  5. // - [Chinese] http://www.cocos.com/docs/creator/scripting/reference/attributes.html
  6. // - [English] http://www.cocos2d-x.org/docs/editors_and_tools/creator-chapters/scripting/reference/attributes/index.html
  7. // Learn life-cycle callbacks:
  8. // - [Chinese] http://www.cocos.com/docs/creator/scripting/life-cycle-callbacks.html
  9. // - [English] http://www.cocos2d-x.org/docs/editors_and_tools/creator-chapters/scripting/life-cycle-callbacks/index.html
  10. cc.Class({
  11. extends: cc.Component,
  12. properties: {
  13. rotAngle: 0, //旋转角度
  14. rotTime: 0, //旋转时间
  15. rotDir: 1, //旋转方向 1为顺时针 -1为逆时针
  16. rotType: 0, //0为沿顺时针或者逆时针一直旋转 1为顺时针和逆时针组合
  17. haveProp: 0
  18. },
  19. // LIFE-CYCLE CALLBACKS:
  20. onLoad: function () {
  21. },
  22. initProperties: function (configure) {
  23. this.rotAngle = configure.angle;
  24. this.rotTime = configure.time;
  25. this.rotDir = configure.dir;
  26. this.rotType = configure.type;
  27. for (let i = 0; i < this.node.children.length; i++) {
  28. var circle = this.node.getChildByName("c" + i);
  29. circle.colorType = Math.floor(i / 5);
  30. }
  31. this.startActiton();
  32. },
  33. startActiton: function () {
  34. if (this.rotType == 0) {
  35. var rotateBy = cc.rotateBy(this.rotTime, this.rotAngle * this.rotDir);
  36. this.node.runAction(cc.repeatForever(rotateBy));
  37. }
  38. else if (this.rotType == 1) {
  39. var rotateBy1 = cc.rotateBy(this.rotTime, this.rotAngle * this.rotDir);
  40. var rotateBy2 = cc.rotateBy(this.rotTime, -this.rotAngle * this.rotDir);
  41. this.node.runAction(cc.repeatForever(cc.sequence(rotateBy1, rotateBy2)));
  42. }
  43. },
  44. pauseAction: function () {
  45. this.node.pauseAllActions();
  46. },
  47. resumeAction: function () {
  48. this.node.resumeAllActions();
  49. },
  50. start() {
  51. },
  52. });