12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- cc.Class({
- extends: cc.Component,
- properties: {
- },
- onLoad () {
- cc.director.getCollisionManager().enabled=true;
- cc.director.getCollisionManager().enabledDebugDraw = false;
- },
- start () {
- },
- /**
- * 鱼钩碰撞到鱼回调
- * @param {*} other
- * @param {*} self
- */
- onCollisionEnter:function(other,self){
- if (!Module.isCollision || other.tag == -1) return;
- if (other.node.group == 'fishing'){
- window.Utils.playSound('sound/fish' , 2, false);
- var leve = other.tag; //获取鱼的种类 (根据鱼的品级判断多少钱)
- this.addFishing(leve);
- Module.fishingNum += window.Utils.getFishingWeight(leve);
- Module.gameObj.setFishingLabel();
- other.node.removeFromParent();
- Module.nonceFishingArr.push(leve);
- return ;
- }
- },
- /**
- * 碰到鱼后加金币动画跟鱼挂在钩上动画
- * @param {*} tag 鱼的tag值
- */
- addFishing: function(tag) {
- var money = window.Utils.getFishingPrice(tag)
- var size = cc.view.getVisibleSize();
- Module.nonceMoney += money;
- //显示增加金币
- {
- var label = cc.instantiate(Module.addMoneyLabel);
- label.getChildByName('num').getComponent(cc.Label).string = ';' + money;
- if (this.node.x > size.width/2) {
- label.x = this.node.x + 200;
- } else {
- label.x = this.node.x -200;
- }
- if (label.x < 200 ) label.x = this.node.x + 200;
- if (label.x > size.width - 200) label.x = this.node.x -200;
-
- label.y = this.node.y - 50;
- Module.goFishingObj.node.addChild(label)
-
- label.runAction(cc.sequence(cc.delayTime(0) , cc.moveBy(0.3, cc.v2(0 , 60)), cc.removeSelf()));
- }
- cc.loader.loadRes('fishing/fishing' + (tag+1), cc.SpriteFrame, function(err, spFrame) {
- if (err) {
- cc.log(err.message || err);
- return;
- }
- let node = new cc.Node('fishing');
- var sprite = node.addComponent(cc.Sprite);
- sprite.spriteFrame = spFrame;
- node.anchorY = 1;
- // node.anchorX = 0.5;
- var x = window.Utils.random(1, 7);
- node.x = (window.Utils.random(1,2) == 1) ? x : -x;
- node.x -= 15;
- node.y = -100;
- node.rotation = -90;
- this.node.addChild(node);
- node.runAction(cc.repeatForever(cc.sequence(cc.rotateBy(0.5 , 30), cc.rotateBy(0.5 , -30))));
- }.bind(this));
- }
- // update (dt) {},
- });
|