ArtistMan.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. cc.Class({
  2. extends: cc.Component,
  3. properties: {
  4. nickLabel: cc.Label,
  5. runMan: cc.Node,
  6. direction: {
  7. get: function () {
  8. if (!this._direction) {
  9. this._direction = 1;
  10. }
  11. return this._direction;
  12. },
  13. set: function (value) {
  14. this._direction = value;
  15. }
  16. }
  17. },
  18. init(artistData) {
  19. this.artistData = artistData;
  20. this.nickLabel.string = artistData.nick;
  21. },
  22. // LIFE-CYCLE CALLBACKS:
  23. onLoad () {
  24. // let direction = (Math.random() - 0.5) * 2; //初始方向{1: 向左; -1: 向右}
  25. this.node.x = Math.random() * 350 * this.direction;
  26. this.node.y = 20;
  27. let moveLeftToRight = cc.moveTo(5, cc.v2(280, this.node.y));
  28. let moveRightToLeft = cc.moveTo(5, cc.v2(-280, this.node.y));
  29. let directionRightToLeftCallback = cc.callFunc(() => {
  30. this.runMan.runAction(cc.scaleTo(0, -1, 1));
  31. });
  32. let directionLeftToRightCallback = cc.callFunc(() => {
  33. this.runMan.runAction(cc.scaleTo(0, 1, 1));
  34. });
  35. if(this.direction < 0) {
  36. this.runMan.scaleX = -1;
  37. let ac = cc.repeatForever(
  38. cc.sequence([
  39. moveLeftToRight,
  40. directionLeftToRightCallback,
  41. moveRightToLeft,
  42. directionRightToLeftCallback,
  43. ])
  44. )
  45. this.node.runAction(ac);
  46. } else {
  47. let ac = cc.repeatForever(
  48. cc.sequence([
  49. moveRightToLeft,
  50. directionRightToLeftCallback,
  51. moveLeftToRight,
  52. directionLeftToRightCallback
  53. ])
  54. )
  55. this.node.runAction(ac);
  56. }
  57. },
  58. // update (dt) {},
  59. });