hook.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. cc.Class({
  2. extends: cc.Component,
  3. properties: {
  4. },
  5. onLoad () {
  6. cc.director.getCollisionManager().enabled=true;
  7. cc.director.getCollisionManager().enabledDebugDraw = false;
  8. },
  9. start () {
  10. },
  11. /**
  12. * 鱼钩碰撞到鱼回调
  13. * @param {*} other
  14. * @param {*} self
  15. */
  16. onCollisionEnter:function(other,self){
  17. if (!Module.isCollision || other.tag == -1) return;
  18. if (other.node.group == 'fishing'){
  19. window.Utils.playSound('sound/fish' , 2, false);
  20. var leve = other.tag; //获取鱼的种类 (根据鱼的品级判断多少钱)
  21. this.addFishing(leve);
  22. Module.fishingNum += window.Utils.getFishingWeight(leve);
  23. Module.gameObj.setFishingLabel();
  24. other.node.removeFromParent();
  25. Module.nonceFishingArr.push(leve);
  26. return ;
  27. }
  28. },
  29. /**
  30. * 碰到鱼后加金币动画跟鱼挂在钩上动画
  31. * @param {*} tag 鱼的tag值
  32. */
  33. addFishing: function(tag) {
  34. var money = window.Utils.getFishingPrice(tag)
  35. var size = cc.view.getVisibleSize();
  36. Module.nonceMoney += money;
  37. //显示增加金币
  38. {
  39. var label = cc.instantiate(Module.addMoneyLabel);
  40. label.getChildByName('num').getComponent(cc.Label).string = ';' + money;
  41. if (this.node.x > size.width/2) {
  42. label.x = this.node.x + 200;
  43. } else {
  44. label.x = this.node.x -200;
  45. }
  46. if (label.x < 200 ) label.x = this.node.x + 200;
  47. if (label.x > size.width - 200) label.x = this.node.x -200;
  48. label.y = this.node.y - 50;
  49. Module.goFishingObj.node.addChild(label)
  50. label.runAction(cc.sequence(cc.delayTime(0) , cc.moveBy(0.3, cc.v2(0 , 60)), cc.removeSelf()));
  51. }
  52. cc.loader.loadRes('fishing/fishing' + (tag+1), cc.SpriteFrame, function(err, spFrame) {
  53. if (err) {
  54. cc.log(err.message || err);
  55. return;
  56. }
  57. let node = new cc.Node('fishing');
  58. var sprite = node.addComponent(cc.Sprite);
  59. sprite.spriteFrame = spFrame;
  60. node.anchorY = 1;
  61. // node.anchorX = 0.5;
  62. var x = window.Utils.random(1, 7);
  63. node.x = (window.Utils.random(1,2) == 1) ? x : -x;
  64. node.x -= 15;
  65. node.y = -100;
  66. node.rotation = -90;
  67. this.node.addChild(node);
  68. node.runAction(cc.repeatForever(cc.sequence(cc.rotateBy(0.5 , 30), cc.rotateBy(0.5 , -30))));
  69. }.bind(this));
  70. }
  71. // update (dt) {},
  72. });