示例显示服务器返回内容

This commit is contained in:
宝爷
2019-10-13 21:04:55 +08:00
parent 8692bb2a89
commit 50819b97a1
2 changed files with 98 additions and 8 deletions

View File

@@ -9,21 +9,26 @@ const { ccclass, property } = cc._decorator;
@ccclass
export default class NewClass extends cc.Component {
@property
text: string = 'hello';
@property(cc.Label)
textLabel: cc.Label = null;
@property(cc.Label)
urlLabel: cc.Label = null;
@property(cc.RichText)
msgLabel: cc.RichText = null;
private lineCount: number = 0;
onLoad() {
let Node = new NetNode();
Node.init(new WebSock(), new DefStringProtocol());
Node.setResponeHandler(0, (cmd: number, data: NetData) => {
console.log(`${data}`);
Node.setResponeHandler(0, (cmd: number, data: NetData) => {
if (this.lineCount > 5) {
let idx = this.msgLabel.string.search("\n");
this.msgLabel.string = this.msgLabel.string.substr(idx + 1);
}
this.msgLabel.string += `${data}\n`;
++this.lineCount;
});
NetManager.getInstance().setNetNode(Node);
}
onConnectClick() {