TranslationMode.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. moveDir:1, //移动方向 1为向右 -1为向左
  14. moveTime:0, //移动时间
  15. moveDistance:0 //移动距离
  16. },
  17. // LIFE-CYCLE CALLBACKS:
  18. onLoad: function()
  19. {
  20. },
  21. initProperties: function(configure)
  22. {
  23. this.moveDistance = configure.distance;
  24. this.moveTime = configure.time;
  25. this.moveDir = configure.dir;
  26. for (let i = 0; i < this.node.children.length; i++) {
  27. var circle = this.node.getChildByName("t"+i);
  28. circle.colorType = Math.floor(i/4);
  29. }
  30. this.startActiton();
  31. },
  32. startActiton: function()
  33. {
  34. var moveBy = cc.moveBy(this.moveTime,cc.p(this.moveDistance*this.moveDir,0));
  35. this.node.runAction(cc.repeatForever(moveBy));
  36. },
  37. pauseAction: function()
  38. {
  39. this.node.pauseAllActions();
  40. },
  41. resumeAction: function()
  42. {
  43. this.node.resumeAllActions();
  44. },
  45. start () {
  46. },
  47. update: function(dt)
  48. {
  49. if (this.moveDir==1)
  50. {
  51. if (this.node.x >= (this.node.width/2+cc.winSize.width/2))
  52. {
  53. this.node.position = cc.p(-(this.node.width/2+this.node.width-cc.winSize.width/2),this.node.y);
  54. }
  55. }
  56. else
  57. {
  58. if (this.node.x <= -(this.node.width/2+cc.winSize.width/2))
  59. {
  60. this.node.position = cc.p((this.node.width/2+this.node.width-cc.winSize.width/2),this.node.y);
  61. }
  62. }
  63. },
  64. });