/** * 鱼游动动作 */ cc.Class({ extends: cc.Component, properties: { }, onLoad () { this.windowSize=cc.view.getVisibleSize(); this.leve = this.getComponent(cc.BoxCollider).tag; this.flag = true; if (this.leve >= 21 ) { this.node.getChildByName("light").runAction(cc.repeatForever(cc.sequence(cc.delayTime(0) , cc.rotateBy(7, 360)))); } }, start () { this.node.x = window.Utils.random(-10, this.windowSize.width + 10); this.bathingCourse(window.Utils.random(1,2)); }, /** * 鱼游动路线 *@param {*} value 动作类型值 */ bathingCourse : function (value) { var b = this.node.x < this.windowSize.width / 2; if (value == 1) { this.course1(b); } else if (value == 2) { this.course2(b); } // this.course3(); }, /** * 循环左右游 * @param {*} b 方向 */ course1: function(b) { var x = 0; if (b) { x = this.windowSize.width + 50; this.node.scaleX = 1; } else { x = -50; this.node.scaleX = -1; } var dl = parseFloat(Math.abs(x - this.node.x) / 1000); var speed = window.Utils.random(2,6); var move = cc.moveTo(dl * (speed + 0.5), cc.v2(x, this.node.y)); this.node.runAction(cc.sequence(move , cc.callFunc(function() { this.course1(this.node.x < this.windowSize.width / 2); }.bind(this)))); }, /** * 循环斜着游 * @param {*} b 方向 */ course2: function(b) { var x = 0, y = 0; if (b) { x = this.windowSize.width + 50; y = this.node.y + 200; this.node.scaleX = 1; } else { x = -50; y = this.node.y - 200; this.node.scaleX = -1; } var dl = parseFloat(Math.abs(x - this.node.x) / 1000); var move = cc.moveTo(dl * 3, cc.v2(x, y)); this.node.runAction(cc.sequence(move , cc.callFunc(function() { this.course2(this.node.x < this.windowSize.width / 2); }.bind(this)))); }, /** * 看到鱼钩快速靠近 * @param {*} pos */ course3: function(pos) { console.log("--course3---"); // this.node.stopAllActions(); var bezier = [cc.v2(0,0), cc.v2(50,100), cc.v2(100,0)]; var bezierBy = cc.bezierBy(0.8, bezier); var fc = cc.callFunc(function(){ // sp.destroy(); },this); this.node.runAction(cc.sequence(bezierBy, fc)); }, /** * 看到鱼钩快速躲闪 * @param {*} pos */ course4: function() { }, course5: function() { }, course6: function() { }, course7: function() { }, update (dt) { return; }, });