Quantcast
Channel: Cocos中文社区 - 最新帖子
Viewing all articles
Browse latest Browse all 495283

请教一个关于Socket.io的问题!

$
0
0

我使用您教我的方法4
这是我的代码

//socket.my.js
var Socket = {
    _instance : null,
    get instance() {
        if (!this._instance) {
            this._instance = io('http://127.0.0.1:3000');
            return this._instance;
        }
    }
};
module.exports = Socket;

//引用

var Socket = require('socket.my');

cc.Class({
    extends: cc.Component,

    properties: {
        
    },

    onLoad: function () {
        
    },
    
    onBtnLoginClicked: function () {
        ````````````
                Socket.instance.emit('login',User);
                Socket.instance.on('login',function(msg){
                    cc.log('111');
                    if(msg.status){
                        LblHint.string = '用户名密码正确!';
                        var tmpAnmi = cc.find("Login/Form").getComponent(cc.Animation);
                        var animation = tmpAnmi;
                        EditBoxName.string = '';
                        EditBoxPwd.string = '';
                        tmpAnmi.play("LoginFormOut");
                        animation.on('stop',self.LoginFormAnimOut,this);
                    }else{
                        LblHint.string = '用户名密码错误!';
                    }
                });
         ```````````
    },

});

Viewing all articles
Browse latest Browse all 495283

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>