PaomaLayer.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import EventMgr from "../base/EventMgr";
  2. cc.Class({
  3. extends: cc.Component,
  4. properties: {
  5. maskNode: cc.Node,
  6. paoNode: cc.Node,
  7. labPao: cc.RichText,
  8. },
  9. // LIFE-CYCLE CALLBACKS:
  10. onLoad () {
  11. this.node.opacity = 0;
  12. },
  13. start () {
  14. this.startX = 267;
  15. this.withX = this.maskNode.width;
  16. this.contentArr = [];
  17. EventMgr.on('paopao', this.goScroll, this);
  18. },
  19. setShowOrHide(bActive){
  20. this.node.opacity = 0;
  21. if(bActive){
  22. if(this.paoNode.getActionByTag(0) && !this.paoNode.getActionByTag(0).isDone()){
  23. this.node.opacity = 255;
  24. }
  25. }
  26. },
  27. goScroll(msg){
  28. this.contentArr.push(msg);
  29. if(this.paoNode.getActionByTag(0) && !this.paoNode.getActionByTag(0).isDone())
  30. return;
  31. let self = this;
  32. let scrollFun = ()=>{
  33. let tempTxt = self.contentArr.shift();
  34. if(tempTxt){
  35. self.node.opacity = 255;
  36. self.labPao.string = tempTxt;
  37. self.paoNode.setPosition(self.startX, 1);
  38. let distance = self.withX + self.paoNode.width + 20;
  39. let duration = distance / 100;
  40. let at = cc.moveBy(duration, cc.v2(-distance, 1));
  41. let funcMoveEnd = ()=>{
  42. self.labPao.string = '';
  43. self.paoNode.setPosition(self.startX, 1);
  44. scrollFun();
  45. }
  46. let seq = cc.sequence(at, cc.callFunc(funcMoveEnd));
  47. seq.setTag(0);
  48. self.paoNode.runAction(seq);
  49. }else{
  50. self.node.opacity = 0;
  51. }
  52. }
  53. scrollFun();
  54. },
  55. onDestroy(){
  56. EventMgr.off('paopao', this.goScroll, this);
  57. }
  58. });