123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330 |
- 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);
- }
- },
- });
|