fameLayer.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /**
  2. * 捕捉传说鱼小游戏
  3. */
  4. cc.Class({
  5. extends: cc.Component,
  6. properties: {
  7. fishing: [cc.Node],
  8. btn: cc.Button,
  9. ProgressBar: cc.ProgressBar,
  10. num: cc.Label,
  11. },
  12. onLoad () {
  13. Module.famLayerObj = this;
  14. },
  15. /**
  16. * 初始化鱼的行为跟进度条
  17. */
  18. start () {
  19. //加个点击层,防止穿透到下面的按钮
  20. this.node.on(cc.Node.EventType.TOUCH_START, this.touchBegin.bind(this), this );
  21. this.node.on(cc.Node.EventType.TOUCH_MOVE, this.touchMoving.bind(this), this );
  22. this.node.on(cc.Node.EventType.TOUCH_END, this.touchEnd.bind(this), this );
  23. this.node.on(cc.Node.EventType.TOUCH_CANCEL, this.touchCancel.bind(this), this );
  24. this.btn.node.on('click', this.callback, this);
  25. this.time = 10;
  26. this.num.string = this.time;
  27. this.countTime = 1;
  28. // this.pos1 = this.fishing[0].getPosition();
  29. // this.pos2 = this.fishing[1].getPosition();
  30. // this.pos3 = this.fishing[2].getPosition();
  31. // this.fishing[0].runAction(cc.sequence(cc.delayTime(0) , cc.moveTo(10, cc.v2(178,23))));
  32. // this.fishing[1].runAction(cc.sequence(cc.delayTime(0) , cc.moveTo(10, cc.v2(-144,41))));
  33. // this.fishing[2].runAction(cc.sequence(cc.delayTime(0) , cc.moveTo(10, cc.v2(-33,-39))));
  34. this.fishing[0].runAction(cc.repeatForever(cc.sequence(cc.rotateBy(0.3 , 100), cc.rotateBy(0.3 , -100))));
  35. this.fishing[1].runAction(cc.repeatForever(cc.sequence(cc.rotateBy(0.3 , 100), cc.rotateBy(0.3 , -100))));
  36. this.fishing[2].runAction(cc.repeatForever(cc.sequence(cc.rotateBy(0.3 , 100), cc.rotateBy(0.3 , -100))));
  37. this.node.getChildByName("bg").getChildByName("light").runAction(cc.repeatForever(cc.sequence(cc.delayTime(0),cc.rotateBy(8, 360))));
  38. this.node.getChildByName("bg").getChildByName("line").runAction(cc.repeatForever(cc.sequence(cc.rotateBy(0.5 , 3), cc.rotateBy(0.5 , -3))));
  39. },
  40. /**
  41. * 按钮回调
  42. */
  43. callback: function() {
  44. if (this.ProgressBar.progress >= 1) {
  45. this.time = 10;
  46. this.num.string = this.time;
  47. this.countTime = 1;
  48. this.node.active = false;
  49. this.ProgressBar.progress = 0;
  50. this.initFishingPos();
  51. Module.gameObj.openSellLayer(true);
  52. return;
  53. }
  54. this.ProgressBar.progress += 0.03;
  55. },
  56. initFishingPos: function() {
  57. // console.log("----this.pos1---: " , this.pos1);
  58. // this.fishing[0].setPosition(cc.v2(this.pos1.x , this.pos1.y));
  59. // this.fishing[1].setPosition(cc.v2(this.pos2.x, this.pos2.y));
  60. // this.fishing[2].setPosition(cc.v2(this.pos3.x, this.pos3.y));
  61. },
  62. fishingAction: function() {
  63. // this.fishing[0].stopAllActions();
  64. // this.fishing[1].stopAllActions();
  65. // this.fishing[2].stopAllActions();
  66. // this.fishing[0].runAction(cc.sequence(cc.delayTime(0) , cc.moveTo(10, cc.v2(178,23))));
  67. // this.fishing[1].runAction(cc.sequence(cc.delayTime(0) , cc.moveTo(10, cc.v2(-144,41))));
  68. // this.fishing[2].runAction(cc.sequence(cc.delayTime(0) , cc.moveTo(10, cc.v2(-33,-39))));
  69. },
  70. update (dt) {
  71. ++this.countTime;
  72. if (this.countTime % 60 == 0 && this.time >0 && this.ProgressBar.progress < 1) {
  73. this.countTime = 1;
  74. this.time -= 1;
  75. this.num.string = this.time;
  76. }
  77. if (this.time < 1) {
  78. this.time = 10;
  79. this.num.string = this.time;
  80. this.countTime = 1;
  81. this.node.active = false;
  82. this.ProgressBar.progress = 0;
  83. this.initFishingPos();
  84. Module.gameObj.openSellLayer(false);
  85. }
  86. if (this.ProgressBar.progress >= 1 && this.ProgressBar.progress != 1) {
  87. this.ProgressBar.progress = 1;
  88. }
  89. },
  90. touchBegin:function(touch,event){
  91. },
  92. touchMoving:function(touch,event){
  93. },
  94. touchEnd:function(touch,event){
  95. },
  96. touchCancel:function(touch,event){
  97. },
  98. });