最近搜索

第16节 显示其它玩家手中的牌,处理位置代码

浏览:432
管理员 2021-10-10 14:27

image.png

image.png



代码如下:

image.png

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




把队友的牌缩小一点

image.png


image.png

 cardNode.scale = 0.5;




对play-node 里面的6个pos  进行位置的调整。

image.png

联系站长

站长微信:xiaomao0055

站长QQ:14496453