var ZYGameTool = require('GameTool'); cc.Class({ extends: cc.Component, properties: { clickFlag: true, homeButtons: {type: cc.Button, default: []}, buttonsName: null, coinLabel: cc.Label, bgmClip: {type: cc.AudioClip, default: null}, //背景音乐 logoNode: cc.Node, cactursNode: cc.Node, maskLayer: cc.Prefab, settingLayer: cc.Prefab, helpLayer: cc.Prefab, coinNode: cc.Node, }, // LIFE-CYCLE CALLBACKS: onLoad() { this.setLocalDataItem(); this.buttonsName = {redBagBtn: 0, giftBtn: 1, redBtn: 2, startBtn: 3, settingBtn: 4, helpBtn: 5, signBtn: 6}; cc.debug.setDisplayStats(false); //首页按钮注册监听 for (var i in this.homeButtons) { this.homeButtons[i].node.scale = 0; this.homeButtons[i].node.on("click", this.gameClickCall, this); } this.homeEffect(); }, start() { if (isFirstInGame) { ZYGameTool.getInstance().loadSpriteFrame(function () { cc.director.preloadScene("mainScene"); isFirstInGame = false; this.init(); }.bind(this)); } else { this.init(); } ZYGameTool.getInstance().OpenAd("banner", "banner"); }, init: function () { this.setCoinLabel(); //播放背景声音 zy.playBgMusic(this.bgmClip, true) }, /** * 初始化设置游戏所需本地化数据 */ setLocalDataItem: function () { coinNum = ZYGameTool.getInstance().getIntegerForKey(localDataItem.coinNum, 100);//默认金币 playeSound = ZYGameTool.getInstance().getIntegerForKey(localDataItem.playeSound, 1);//音效开关 playeMusic = ZYGameTool.getInstance().getIntegerForKey(localDataItem.playeMusic, 1);//背景音乐开关 console.log("--playeMusic-: ", playeMusic); console.log("--playeSound-: ", playeSound); }, /** *设置金币 */ setCoinLabel: function () { if (coinNum === undefined || coinNum === 'NAN') coinNum = 0; this.coinLabel.string = coinNum; }, /** * 首页的动画 */ homeEffect: function () { var logoHeight = 1000; var initLogoHeight = this.logoNode.parent.y; { this.logoNode.y += logoHeight; this.cactursNode.y += logoHeight; } //logo { var actions = []; var ac1 = cc.moveBy(0.2, cc.v2(0, logoHeight * -1 - 50)); var ac2 = cc.moveBy(0.1, cc.v2(0, 50)); var ac3 = cc.scaleTo(0.1, 1, 0.6); var ac4 = cc.scaleTo(0.1, 1, 1); actions.push(ac1); actions.push(ac2); actions.push(ac3); actions.push(ac4); // actions2.concat(0,actions.length-1); var actions2 = [].concat(actions); console.log("actions2", actions2); this.logoNode.runAction(cc.sequence( cc.delayTime(0.2), cc.moveBy(0.2, cc.v2(0, logoHeight * -1 - 50)), cc.moveBy(0.1, cc.v2(0, 50)), cc.scaleTo(0.1, 1, 0.6), cc.scaleTo(0.1, 1, 1), cc.delayTime(1.5), cc.callFunc(function (node) { node.runAction(cc.repeatForever( cc.sequence( cc.rotateTo(1.5, 1), cc.rotateTo(1.5, -1), ) )) }.bind(this), this.constructor) )); this.cactursNode.runAction(cc.sequence( cc.delayTime(0.35 + 0.2), cc.moveBy(0.2, cc.v2(0, logoHeight * -1 - 50)), cc.moveBy(0.1, cc.v2(0, 50)), cc.scaleTo(0.1, 1, 0.6), cc.scaleTo(0.1, 1, 1), cc.delayTime(0.5), cc.callFunc(function (node) { node.runAction(cc.repeatForever( cc.sequence( cc.scaleTo(1.5, 1, 0.85), cc.scaleTo(1.5, 1, 1), ) )) }.bind(this), this.constructor) )); } //按钮统一动画 { this.node.runAction(cc.sequence( cc.delayTime(0.6 + 0.2), cc.callFunc(function () { var dl = 0.05; for (var i in this.homeButtons) { this.homeButtons[i].node.runAction(cc.sequence( cc.delayTime(dl * i), cc.scaleTo(0.5, 1, 1), )); } }.bind(this)) )); this.homeButtons[this.buttonsName.startBtn].node.runAction(cc.sequence(cc.delayTime(1.8), cc.callFunc(function (node) { node.runAction(cc.repeatForever( cc.sequence( cc.scaleTo(2.5, 0.85), cc.scaleTo(2.5, 1), ) )) }.bind(this), this.homeButtons[this.buttonsName.startBtn]))) } { this.homeButtons[this.buttonsName.redBtn].node.runAction(cc.sequence(cc.delayTime(1.8), cc.callFunc(function (node) { node.runAction(cc.repeatForever( cc.sequence(cc.spawn(cc.rotateTo(0.8, 7), cc.scaleTo(0.8, 0.9)), cc.spawn(cc.rotateTo(0.8, -7), cc.scaleTo(0.8, 1.0))) )) }.bind(this), this.homeButtons[this.buttonsName.redBtn]))); var finger = this.homeButtons[this.buttonsName.redBtn].node.parent.getChildByName("finger"); finger.runAction(cc.sequence(cc.delayTime(1.8),cc.scaleTo(0.5, 0.6), cc.callFunc(function (node) { node.runAction( cc.repeatForever( cc.sequence( cc.show(), cc.blink(2, 5), cc.delayTime(2), cc.hide(), cc.delayTime(5), ) )) }.bind(this), finger))); } }, gameClickCall: function (target) { var name = target.node.name; console.log("--name--: ", name); if (name === "startBtn") { this.gameStartClick(); } else if (name === "helpBtn") { this.gameHelpClick(10); } else if (name === "redBtn") { this.gameRedClick(); } else if (name === "settingBtn") { this.gameSettingClick(); } }, gameHelpClick: function () { var helpLayer = cc.instantiate(this.helpLayer); helpLayer.parent = this.node; helpLayer.zIndex = 1000; }, gameSettingClick: function () { var settingNode = cc.instantiate(this.settingLayer); settingNode.parent = this.node; settingNode.zIndex = 1000; }, gameRedClick: function (pos) { ZYGameTool.getInstance().OpenAd("home_lqjb", "video", function () { this.coinAction(50); coinNum += 10; this.setCoinLabel(); ZYGameTool.getInstance().setIntegerForKey(localDataItem.coinNum, coinNum); console.log("---debug---成功---"); }.bind(this), function () { console.log("---debug---失败---"); }.bind(this), ) }, coinAction: function (num) { var dl = 0.15; var bezier = [cc.v2(0, 0), cc.v2(-300, 100), cc.v2(this.coinNode.x - 60, this.coinNode.y)]; for (var i = 0; i < num; i++) { var node = zy.getSprite("common/coin"); node.setPosition(cc.v2(0, 0)); node.scale = 0; node.zIndex = 100 - i; this.node.addChild(node); node.runAction(cc.speed(cc.sequence(cc.delayTime(dl * i), cc.scaleTo(0.2, 1, 1), cc.delayTime(0.1), cc.bezierTo(0.2, bezier), cc.fadeOut(0.05), cc.callFunc(function (node) { node.removeFromParent(); }.bind(this), node)), num / 10)); } }, gameStartClick: function () { if (!this.clickFlag) return; zy.stopBgMusic(); this.clickFlag = false; cc.director.loadScene("mainScene"); // this.node.runAction(cc.fadeOut(0.8)); // this.node.runAction(cc.sequence(cc.delayTime(0.5), cc.callFunc(function () { // cc.director.loadScene("mainScene"); // }))); }, // update (dt) {}, onDestroy() { //关闭所有音乐、音效 cc.audioEngine.stopAll(); //移除所有事件监听 cc.game.targetOff(this); } });