var WxCommon = require("../extra/WxCommon") //sdk接入 var Sdk = require('../Sdk/sdk') var sdk = new Sdk('吃鸡大兵') cc.Class({ extends: cc.Component, properties: { sceneManager: { default: null, type: cc.Node }, bgNode: { default: null, type: cc.Node }, bg1Node: { default: null, type: cc.Node }, ShareStrategyNode: {//游戏攻略图片节点 default: null, type: cc.Node }, planeMoveNode: { default: null, type: cc.Node }, bgMusic: { //背景音乐 default: null, url: cc.AudioClip }, score: { //玩家分数 default: null, type: cc.Label }, SignAtlas:{ default:null, type:cc.SpriteAtlas, }, bgspeed:5, feiendtex: null, otherGamesIndex : 0, timerid : null, }, // use this for initialization onLoad: function () { UserInfo.getCurWeekScoreValue(); this.WxLogin(); this.initShare(); this.listenGame(); var date = new Date(); var y = date.getFullYear(); var m = date.getMonth() + 1; var w = date.getDate(); var currentTime = y + "-" + m +"-" + w; var timeStr = UserInfo.getString("curTime"); if ((timeStr == null) || currentTime != timeStr) { UserInfo.setString("curTime",currentTime); UserInfo.setString("coinCount", 5); } if (UserInfo.platform == 1) { wx.setPreferredFramesPerSecond(60); } // this.ShareStrategyNode.on(cc.Node.EventType.TOUCH_END, this.onTouchEnd, this); this.onPlaneMoveing(); //SDK接入 sdk.showAdIcon(100,500,this.node); var launchOptions = wx.getLaunchOptionsSync(); console.log(launchOptions.scene); sdk.initSdk(launchOptions.scene); }, start() { this.feiendtex = new cc.Texture2D(); if (cc.vv == undefined) { cc.vv = {}; } // cc.view.setDesignResolutionSize(750, 1334, cc.ResolutionPolicy.SHOW_ALL); }, WxLogin() { if (UserInfo.platform != 1) { return; } wx.login({ success: function (res) { if (res.code) { var js_code = res.code; } else { console.log('登录失败!' + res.errMsg) } } }); }, initShare(data) { let datavalue = UserInfo.getString('allscore'); let key = UserInfo.getCurWeekScoreValue(); if (UserInfo.IsEmpty(datavalue)) { UserInfo.setString('allscore', key); return; } let datalist = datavalue.split('*'); let removeIndex = -1; for (let index = 0; index < datalist.length; ++index) { if (key == datalist[index]) { // UserInfo.removeString(datalist[index]); removeIndex = index; } } if (removeIndex != -1) { datalist.splice(removeIndex, 1); } WxCommon.RemoveUserCloudStorage(datalist, this, this.RemoveScoreKey); // this.RemoveScoreKey(datalist, true); }, listenGame() { if (UserInfo.platform == 1) { // var date = UserInfo.GetNowFormatDate(); WxCommon.SetEnableDebug(false); WxCommon.OnShow(null, this, null); WxCommon.ShowShareMenu(); WxCommon.OnShareAppMessage(null, this, this.shareCallback); WxCommon.GetSystemInfo(null, this, null); } }, onEnable: function () { this.score.string = "" + UserInfo.getGold(); //this.loadPrisonSP(); this.bgMusicID = cc.audioEngine.playMusic(this.bgMusic, true, 1); }, onDisable: function () { cc.audioEngine.uncache(this.bgMusic); }, onDestroy: function () { }, onGameStart: function () { this.sceneManager.getComponent('SceneManager').changeCanvasByName('Game'); // var sdk = new Sdk("元气骑士"); // var canvas = wx.createCanvas(); // sdk.openQrcode(); // console.log("元气骑士"); // // var data = wx.getLaunchOptionsSync(); // sdk.initSdk(data.scene); // sdk.showAdIcon(23,4,canvas); }, onPlaneMoveing: function() { var planeNode = this.planeMoveNode.getChildByName("plane"); planeNode.runAction(cc.repeatForever(cc.moveTo(4,cc.p(0,1600)))); }, onGoShop: function () { this.sceneManager.getComponent('SceneManager').changeCanvasByName('Shop'); }, onShowStrategy: function () { this.ShareStrategyNode.active = true; this.createTimer(); }, // updateOtherGames: function(self) { // self.otherGamesIndex = (self.otherGamesIndex + 1 + WxCommon.otherGameCount) % WxCommon.otherGameCount; // self.createTimer(); // }, createTimer: function() { var self = this; var updateOtherGames = function() { self.otherGamesIndex = (self.otherGamesIndex + 1 + WxCommon.otherGameCount) % WxCommon.otherGameCount; self.ShareStrategyNode.getChildByName("othergames").getComponent(cc.Sprite).spriteFrame = self.SignAtlas.getSpriteFrame('games' + self.otherGamesIndex); self.createTimer(); }; if (this.ShareStrategyNode.active == true) { this.timerid = setTimeout(updateOtherGames,2000); } }, killTimer: function() { if (this.timerid != null) { clearTimeout(this.timerid); this.timerid = null; } }, onTouchEnd: function (event) { this.hideNode(); }, hideNode: function () { if (this.ShareStrategyNode.active) { this.killTimer(); this.ShareStrategyNode.active = false; } }, SaveImg: function () { if (UserInfo.platform == 1) { var path = UserInfo.ewmurl; WxCommon.SaveImageToPhotosAlbum(path, this, this.hideNode); } }, bgMove:function(speed){ var bgPositionY = this.bgNode.getPosition().y; var bg1PositionY = this.bg1Node.getPosition().y; this.bgNode.setPosition(cc.v2(0,bgPositionY - speed)); this.bg1Node.setPosition(cc.v2(0,bg1PositionY - speed)); }, //检查是否要重置位置 checkBgReset:function(){ var bgYMax = this.bgNode.getContentSize().height; if(this.bgNode.getPosition().y <= -bgYMax) { this.bgNode.setPosition(cc.v2(0,bgYMax-7)); //会有缝隙 所以设置成小一点 有拼接 } if(this.bg1Node.getPosition().y <= -bgYMax) { this.bg1Node.setPosition(cc.v2(0,bgYMax-7)); } }, onButtonRank: function (event, optData) { if (UserInfo.platform != 1 || !cc.vv.isRank) { return; } wx.postMessage({ method: 'showFriendRank', data: optData }); cc.find("Canvas/PHB").getChildByName("BtnPHBClose").active = (optData == "true"); cc.find("Canvas/PHB").getChildByName("bg").active = (optData == "true"); if ("true" == optData) { this.showRank(); } if ("false" == optData) { wx.postMessage({ method: 'hideRank', data: optData }); cc.find("Canvas/PHB").active = false; } }, showRank() { if (UserInfo.platform == 1 && cc.vv.isRank) { let openDataContext = wx.getOpenDataContext(); let sharedCanvas = openDataContext.canvas; this.feiendtex.initWithElement(sharedCanvas); this.feiendtex.handleLoadedTexture(); cc.find("Canvas/PHB").getChildByName("feiendrank").getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(this.feiendtex); //cc.find("Canvas/PHB").getChildByName("feiendrank").setContentSize(720,1280); var scale = Math.min(750 / this.feiendtex.width, 1334 / this.feiendtex.height); cc.find("Canvas/PHB").getChildByName("feiendrank").setContentSize(this.feiendtex.width * scale, this.feiendtex.height * scale); cc.find("Canvas/PHB").active = true; } }, // called every frame update: function (dt) { if (cc.find("Canvas/PHB").active == true) { this.showRank(); } this.bgMove(this.bgspeed); this.checkBgReset(); var planeNode = this.planeMoveNode.getChildByName("plane"); if(planeNode.getPosition().y==1600) { planeNode.setPosition(cc.v2(0,-1600)); } }, // loadPlaneSP: function () { // //人物根据玩家记录等级动态加载 // let prisonSprite = this.plane.getComponent(cc.Sprite); // cc.loader.loadRes('texture/Game/Airplane' + UserInfo.getCurrentPrison(), cc.SpriteFrame, function (err, spriteframe) { // planeSprite.spriteFrame = spriteframe; // }); // }, onCloseStrategy: function() { this.hideNode(); }, onShowOtherGame: function() { if (UserInfo.platform == 1) { var path = WxCommon.otherGameMap.get(this.otherGamesIndex); WxCommon.PreviewImage(path, this, this.hideNode); } }, });