QQ 玩一玩获取用户图像、昵称以及CocosCreator加载图片的几种方式介绍
//设置显示图片
function setImg(imgNode, spriteFrame) {
imgNode.getComponent(cc.Sprite).spriteFrame = spriteFrame;
}
//加载网络图片
function loadImgByUrl(imgNode, remoteUrl, imageType) {
if (!imageType) {
imageType = "png";
}
cc.loader.load({
url: remoteUrl,
type: imageType
}, function (err, texture) {
if (err) {
return;
}
setImg(imgNode, new cc.SpriteFrame(texture));
});
}
//加载手机本地图片
function loadLocal(imgNode, absolutePath) {
cc.loader.load(absolutePath, function (err, texture) {
if (err) {
return;
}
setImg(imgNode, new cc.SpriteFrame(texture));
});
}
module.exports = {
loadImgByUrl: loadImgByUrl,
loadLocal: loadLocal,
setImg: setImg,
};
BK.MQQ.Account.getNick(GameStatusInfo.openId, function (openId, nick) {
cc.log("nick:"+nick);
});
getHead() {
let absolutePath = "GameSandBox://_head/" + GameStatusInfo.openId + ".jpg";
let isExit = BK.fileSystem.accessSync(absolutePath);
cc.log(absolutePath + " is exit :" + isExit);
//如果指定目录中存在此图像就直接显示否则从网络获取
if (isExit) {
Utils.loadLocal(this.head, absolutePath);
} else {
BK.MQQ.Account.getHeadEx(GameStatusInfo.openId, function (oId, imgPath) {
cc.log("openId:" + oId + " imgPath:" + imgPath);
Utils.loadLocal(this.head, imgPath);
}.bind(this));
}
},
CocosCreator开发小游戏示例:Brickengine_Guide
完
到这里就介绍完了,个人能力有限如有错误欢迎指正,如有遗漏欢迎补充。如有疑问欢迎留言一起交流讨论。