import MapConroler from "../../Script/Map"; const { ccclass, property } = cc._decorator; @ccclass export default class shareFriend extends cc.Component { @property(cc.SpriteAtlas) ui: cc.SpriteAtlas = null; onLoad() { } start() { } init(type, shuju) { console.log("111111111", shuju); this.node.getChildByName("level").getComponent(cc.Label).string = shuju.otherLevel + ""; let useravatarIcon = shuju.otherKuang; useravatarIcon = "kuang_" + (parseInt(useravatarIcon) + 1); console.log("3333333", useravatarIcon); if (this.node.getChildByName("kuang")) this.node.getChildByName("kuang").getComponent(cc.Sprite).spriteFrame = this.ui.getSpriteFrame(useravatarIcon); if (shuju.otherAvatarUrl == "" || shuju.otherAvatarUrl == null || shuju.otherAvatarUrl == undefined ) { console.log("头像为空", shuju.otherAvatarUrl); } else if (shuju.otherAvatarUrl == "0" || shuju.otherAvatarUrl == "1" || shuju.otherAvatarUrl == "2" || shuju.otherAvatarUrl == "3" || shuju.otherAvatarUrl == "4" || shuju.otherAvatarUrl == "5" || shuju.otherAvatarUrl == "6" || shuju.otherAvatarUrl == "7" || shuju.otherAvatarUrl == "8" || shuju.otherAvatarUrl == "9" || shuju.otherAvatarUrl == "10" || shuju.otherAvatarUrl == "11" || shuju.otherAvatarUrl == "12" || shuju.otherAvatarUrl == "13" || shuju.otherAvatarUrl == "14" || shuju.otherAvatarUrl == "15" || shuju.otherAvatarUrl == "16" || shuju.otherAvatarUrl == "17") { let useravatar = shuju.otherAvatarUrl; let useravatarTemp = "icon_" + useravatar; console.log("用户头像:", useravatarTemp); console.log("44444444"); if (this.node.getChildByName("iphone")) this.node.getChildByName("iphone").getChildByName("icon").getComponent(cc.Sprite).spriteFrame = this.ui.getSpriteFrame(useravatarTemp); } else this.setPic(shuju.otherAvatarUrl); let name = shuju.otherNickName; if (name == "user" || name == null) name = "你的好友"; else { if (shuju.otherNickName.length >= 7) name = cc.fx.GameTool.subName(shuju.otherNickName, 7); } console.log("7777777"); if (this.node.getChildByName("name")) { console.log("8888888", name); this.node.getChildByName("name").getComponent(cc.Label).string = name + ""; } } helpBtn() { const canvasTemp = cc.find("Canvas"); // 假设 Canvas 节点 if (canvasTemp) { const JiaZai = canvasTemp.getComponent("JiaZai"); if (JiaZai) { JiaZai.startGame(); } } } closeBtn() { this.node.active = false; } public setPic(url) { // console.log("设置头像:", this.data.useravatar); var self = this; console.log("6666666", url); self.node.getChildByName("iphone").getChildByName("icon").active = false; cc.assetManager.loadRemote(url, { ext: '.png' }, (err, texture: cc.Texture2D) => { if (texture) { console.log("设置头像成功", self.node.getChildByName("iphone")); if (self.node.getChildByName("iphone")) { console.log("okokokokokok") var sprite = self.node.getChildByName("iphone").getChildByName("icon").getComponent(cc.Sprite); sprite.spriteFrame = new cc.SpriteFrame(texture); console.log("最终设置成功") self.node.getChildByName("iphone").getChildByName("icon").active = true; } } else { self.node.getChildByName("iphone").getChildByName("icon").active = true; console.log("设置头像失败", url); console.log(err, texture) } }) } update() { } }