| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339 |
- // Learn cc.Class:
- // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/class.html
- // - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/class.html
- // Learn Attribute:
- // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
- // - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/reference/attributes.html
- // Learn life-cycle callbacks:
- // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
- // - [English] https://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html
- cc.Class({
- extends: cc.Component,
- properties: {
- loginlayou: cc.Node
- },
- // LIFE-CYCLE CALLBACKS:
- onLoad () {
- utils.redytoLoadScene("game");
- utils.redytoLoadScene("end");
- utils.redytoLoadScene("teaching");
- utils.isMobile(function () {
- manager_android_js.getNavigator();
- }.bind(this));
- },
- start() {
- // if (manager_android_js != null) {
- // manager_android_js.loginnameger = this;
- // manager_android_js.getNavigator();
- //
- //
- // if (manager_android_js.isiOS == true) {
- // manager_android_js.startGame();
- // }else{
- // this.init();
- // }
- // }
- this.init();
- },
- initStartGame : function(){
- this.init();
- },
- init: function () {
- this._parent = this.loginlayou;
- this.loginlayou.active = true;
- // this.initLeft(PlayerInfo.Left);
- //
- // this.readyRight();
- // this.startCountDownTime();
- // setTimeout(function () {
- //
- // this.matchingSuccess();
- // }.bind(this), 1000)
- this.startButton = UtilsNode.getNode("startButton",this.loginlayou)
- UtilsNode.setOn(this.startButton,function () {
- this.allViewActive(false);
- utils.toLoadScene("game")
- }.bind(this));
- this.gpTeaching = UtilsNode.getNode("gpTeaching",this.loginlayou)
- UtilsNode.setOn(this.gpTeaching,function () {
- this.allViewActive(false);
- utils.toLoadScene("teaching")
- }.bind(this));
- },
- allViewActive(b){
- this.startButton.active = b
- this.gpTeaching.active = b
- },
- //匹配成功
- matchingSuccess: function () {
- // this.initRight(PlayerInfo.Right);
- this.stopCountDownTime();
- // this.handle();
- // manager_android_js.myPlayerInfo = PlayerInfo;
- // this.callbackAudioSource = function () {
- //
- // this.getComponent(cc.AudioSource).volume = 0.5;
- // this.getComponent(cc.AudioSource).play();
- // }
- // this.scheduleOnce(this.callbackAudioSource, 0.05);
- //
- // this.callbackLoadScene = function () {
- // cc.director.loadScene("game");
- // }
- //
- //
- // this.scheduleOnce(this.callbackLoadScene, 1);
- },
- //匹配成功的处理
- handle: function () {
- this.getNode("Cancel").active = false;
- this.getNode("zhao").active = false;
- this.getNode("chenggong").active = true;
- },
- startCountDownTime: function () {
- this.timeData = {
- branch: "00",
- second: "00"
- }
- this.waittime = this.getNode("waittime");
- this.waittime.getComponent(cc.Label).string = this.timeData.branch + ":" + this.timeData.second
- this.time_count = 0;
- this.time_branch = 0;
- this.time_second = 10;
- this.callbackCountDownTime = function () {
- this.time_second++;
- if (this.time_second > 60) {
- this.time_second = 0;
- this.time_branch++;
- }
- this.time_count++;
- //设置秒
- var second;
- if (this.time_second < 10) {
- second = '0' + this.time_second;
- } else {
- second = this.time_second;
- }
- this.timeData.second = second + "";
- var branch;
- if (this.time_branch < 10) {
- branch = '0' + this.time_branch;
- } else {
- branch = this.time_branch;
- }
- this.timeData.branch = branch + "";
- // console.log("我们的时间", this.timeData);
- this.updetaTime(this.timeData);
- }
- this.schedule(this.callbackCountDownTime, 1);
- },
- updetaTime: function (timeData) {
- this.waittime.getComponent(cc.Label).string = timeData.branch + ":" + timeData.second
- },
- //停止倒计时
- stopCountDownTime: function () {
- this.unschedule(this.callbackCountDownTime);
- },
- initLeft: function (data) {
- var temp;
- if (data == null) {
- temp = {
- id: 9527,
- name: "汪汪husky",
- gender: 0,
- head: "https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=857896439,118415596&fm=27&gp=0.jpg"
- // head: "https://www.yuyekeji.cn/media/user/Images/Share.png"
- }
- } else {
- temp = data;
- }
- // temp
- var parent = this.getNode("AvatarMale");
- var playname = this.getNode("playname", parent);
- var Male = this.getNode("Male", parent);
- var Female = this.getNode("Female", parent);
- var mask = this.getNode("mymask", parent);
- var head = mask.getChildByName("head");
- if (temp.gender == 0) {
- Male.active = true;
- Female.active = false;
- } else {
- Male.active = false;
- Female.active = true;
- }
- playname.getComponent(cc.Label).string = temp.name;
- this.loadImg(head, temp.head, 150, 150)
- },
- initRight: function (data) {
- var temp;
- if (data == null) {
- temp = {
- id: 9528,
- name: "妹妹husky",
- gender: 1,
- head: ""
- }
- } else {
- temp = data;
- }
- // temp
- var parent = this.getNode("AvatarFemale");
- var playname = this.getNode("playname", parent);
- var Male = this.getNode("Male", parent);
- var Female = this.getNode("Female", parent);
- var mask = this.getNode("mymask", parent);
- var head = mask.getChildByName("head");
- parent.active = true;
- if (temp.gender == 0) {
- Male.active = true;
- Female.active = false;
- } else {
- Male.active = false;
- Female.active = true;
- }
- playname.getComponent(cc.Label).string = temp.name
- this.loadImg(head, temp.head, 150, 150)
- },
- readyRight: function () {
- var parent = this.getNode("PinkFrameFillColor");
- var left = this.getNode("left", parent);
- var middle = this.getNode("middle", parent);
- var right = this.getNode("right", parent);
- var left_Position = left.getPosition();
- var middle_Position = middle.getPosition();
- var right_Position = right.getPosition();
- // var arrp = [];
- // arrp.push(left_Position);
- // arrp.push(middle_Position);
- // arrp.push(right_Position);
- var arrp = [];
- arrp.push(right_Position);
- arrp.push(middle_Position);
- arrp.push(left_Position);
- var arrn = [];
- arrn.push(left);
- arrn.push(middle);
- arrn.push(right);
- this.count = 0;
- this.callback = function () {
- var temp = arrp[arrp.length - 1];
- arrp.unshift(temp);
- arrp.pop()
- // console.log("操作",arrn);
- if (this.count == arrp.length) {
- // 在第六次执行回调时取消这个计时器
- // this.unschedule(this.callback);
- this.count = 0;
- }
- for (var i = 0; i < arrp.length; i++) {
- arrn[i].x = arrp[i].x;
- }
- this.count++;
- }
- this.schedule(this.callback, 0.5);
- },
- getNode: function (name, parent) {
- if (parent == null) {
- return this._parent.getChildByName(name);
- } else {
- return parent.getChildByName(name);
- }
- },
- //取消匹配
- cancelmatch: function () {
- console.log("取消匹配");
- },
- loadImg: function (container, url, w, h) {
- var newurl = utils.getNewHttpImage(url);
- cc.loader.load(newurl,function (err, texture) {
- var sprite = new cc.SpriteFrame(texture);
- container.getComponent(cc.Sprite).spriteFrame = sprite;
- if (w != null) {
- container.width = w;
- }
- if (h != null) {
- container.height = h;
- }
- });
- },
- // update (dt) {},
- });
|