CircleMode.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. },
  18. // LIFE-CYCLE CALLBACKS:
  19. onLoad: function()
  20. {
  21. },
  22. initProperties: function(configure)
  23. {
  24. this.rotAngle = configure.angle;
  25. this.rotTime = configure.time;
  26. this.rotDir = configure.dir;
  27. this.rotType = configure.type;
  28. for (let i = 0; i < this.node.children.length; i++) {
  29. var circle = this.node.getChildByName("c"+i);
  30. circle.colorType = Math.floor(i/5);
  31. }
  32. this.startActiton();
  33. },
  34. startActiton: function()
  35. {
  36. if (this.rotType == 0)
  37. {
  38. var rotateBy = cc.rotateBy(this.rotTime,this.rotAngle*this.rotDir);
  39. this.node.runAction(cc.repeatForever(rotateBy));
  40. }
  41. else if (this.rotType == 1)
  42. {
  43. var rotateBy1 = cc.rotateBy(this.rotTime,this.rotAngle*this.rotDir);
  44. var rotateBy2 = cc.rotateBy(this.rotTime,-this.rotAngle*this.rotDir);
  45. this.node.runAction(cc.repeatForever(cc.sequence(rotateBy1,rotateBy2)));
  46. }
  47. },
  48. pauseAction: function()
  49. {
  50. this.node.pauseAllActions();
  51. },
  52. resumeAction: function()
  53. {
  54. this.node.resumeAllActions();
  55. },
  56. start () {
  57. },
  58. });