/** * 捕捉传说鱼小游戏 */ cc.Class({ extends: cc.Component, properties: { fishing: [cc.Node], btn: cc.Button, ProgressBar: cc.ProgressBar, num: cc.Label, }, onLoad () { Module.famLayerObj = this; }, /** * 初始化鱼的行为跟进度条 */ start () { //加个点击层,防止穿透到下面的按钮 this.node.on(cc.Node.EventType.TOUCH_START, this.touchBegin.bind(this), this ); this.node.on(cc.Node.EventType.TOUCH_MOVE, this.touchMoving.bind(this), this ); this.node.on(cc.Node.EventType.TOUCH_END, this.touchEnd.bind(this), this ); this.node.on(cc.Node.EventType.TOUCH_CANCEL, this.touchCancel.bind(this), this ); this.btn.node.on('click', this.callback, this); this.time = 10; this.num.string = this.time; this.countTime = 1; // this.pos1 = this.fishing[0].getPosition(); // this.pos2 = this.fishing[1].getPosition(); // this.pos3 = this.fishing[2].getPosition(); // this.fishing[0].runAction(cc.sequence(cc.delayTime(0) , cc.moveTo(10, cc.v2(178,23)))); // this.fishing[1].runAction(cc.sequence(cc.delayTime(0) , cc.moveTo(10, cc.v2(-144,41)))); // this.fishing[2].runAction(cc.sequence(cc.delayTime(0) , cc.moveTo(10, cc.v2(-33,-39)))); this.fishing[0].runAction(cc.repeatForever(cc.sequence(cc.rotateBy(0.3 , 100), cc.rotateBy(0.3 , -100)))); this.fishing[1].runAction(cc.repeatForever(cc.sequence(cc.rotateBy(0.3 , 100), cc.rotateBy(0.3 , -100)))); this.fishing[2].runAction(cc.repeatForever(cc.sequence(cc.rotateBy(0.3 , 100), cc.rotateBy(0.3 , -100)))); this.node.getChildByName("bg").getChildByName("light").runAction(cc.repeatForever(cc.sequence(cc.delayTime(0),cc.rotateBy(8, 360)))); this.node.getChildByName("bg").getChildByName("line").runAction(cc.repeatForever(cc.sequence(cc.rotateBy(0.5 , 3), cc.rotateBy(0.5 , -3)))); }, /** * 按钮回调 */ callback: function() { if (this.ProgressBar.progress >= 1) { this.time = 10; this.num.string = this.time; this.countTime = 1; this.node.active = false; this.ProgressBar.progress = 0; this.initFishingPos(); Module.gameObj.openSellLayer(true); return; } this.ProgressBar.progress += 0.03; }, initFishingPos: function() { // console.log("----this.pos1---: " , this.pos1); // this.fishing[0].setPosition(cc.v2(this.pos1.x , this.pos1.y)); // this.fishing[1].setPosition(cc.v2(this.pos2.x, this.pos2.y)); // this.fishing[2].setPosition(cc.v2(this.pos3.x, this.pos3.y)); }, fishingAction: function() { // this.fishing[0].stopAllActions(); // this.fishing[1].stopAllActions(); // this.fishing[2].stopAllActions(); // this.fishing[0].runAction(cc.sequence(cc.delayTime(0) , cc.moveTo(10, cc.v2(178,23)))); // this.fishing[1].runAction(cc.sequence(cc.delayTime(0) , cc.moveTo(10, cc.v2(-144,41)))); // this.fishing[2].runAction(cc.sequence(cc.delayTime(0) , cc.moveTo(10, cc.v2(-33,-39)))); }, update (dt) { ++this.countTime; if (this.countTime % 60 == 0 && this.time >0 && this.ProgressBar.progress < 1) { this.countTime = 1; this.time -= 1; this.num.string = this.time; } if (this.time < 1) { this.time = 10; this.num.string = this.time; this.countTime = 1; this.node.active = false; this.ProgressBar.progress = 0; this.initFishingPos(); Module.gameObj.openSellLayer(false); } if (this.ProgressBar.progress >= 1 && this.ProgressBar.progress != 1) { this.ProgressBar.progress = 1; } }, touchBegin:function(touch,event){ }, touchMoving:function(touch,event){ }, touchEnd:function(touch,event){ }, touchCancel:function(touch,event){ }, });