


import global from "./global";
cc.Class({
extends: cc.Component,
properties: {
uname : cc.Label,
house_manage_label : cc.Label,
card_node_prefab: cc.Prefab,
card_pos:{
default : [],
type : cc.Node
}
},
onLoad () {
global.gameEventListener.on("change_house_manager", this.changeHouseManager.bind(this));
//接受牌的消息
global.gameEventListener.on("push_card", this.pushCard.bind(this));
},
pushCard(){
console.log("player-node-js-----pushCard");
if(this.getClientId()===global.client.id){
//自己这里不用再发牌了,不用在自己的头像。发牌了。
return;
}
this.cardNodeList = [];
for(let i=0;i<3;i++){
var cardNode = cc.instantiate(this.card_node_prefab);
cardNode.parent = this.node;
let x = 80 * (3-1) * -0.5 +80 * i ;
let y = 0 ;
var pos = cc.v2(x,y);
cardNode.setPosition(this.card_pos[this.index].position.add(pos) );
this.cardNodeList.push(cardNode);
}
},
init(playerData,index){
this.clienId = playerData.id;
this.index = index;
this.uname.string = playerData.nickname;
if(playerData.id==global.house_manage_id){
//判断这个人是不是房主
this.house_manage_label.string ="房主";
}
},
changeHouseManager: function (clientId) {
console.log("player_node---change house manager = " + clientId);
// this.house_manager_label.string = "";
this.house_manage_label.string = "";
if (clientId === this.clienId){
// this.house_manager_label.string = "房主";
this.house_manage_label.string = "房主";
}
},
getClientId(){
return this.clienId;
},
onDestroy(){
console.log("player-node-onDestroy--"+this.uname.string+"销毁了");
//注销他的事件。
global.gameEventListener.off("change_house_manager", this.changeHouseManager);
global.gameEventListener.off("push_card", this.pushCard);
}
});

cardNode.scale = 0.5;

站长微信:xiaomao0055
站长QQ:14496453