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