egret微信好友排行榜制作教程

egret微信好友排行榜制作教程

1 先设置开放域目录
打开game.json文件
{
"deviceOrientation": "portrait",
"openDataContext": "src/myOpenDataContext"
}
2 主域中 存入玩家信息
wx.setUserCloudStorage({
KVDataList: [{ key: 'score', value: "33" }],
success: res => {
console.log(res);

},
fail: res => {
console.log(res);
}
});

3 开放域中 读取数据
<pre>

wx.getFriendCloudStorage({
keyList: ['score'], // 你要获取的、托管在微信后台都key
success: res => {
console.log(res.data);
}
});
</pre>

4 下面最难的就是绘制排行榜了
首先开放域中调用默认的sharecanvas画布 给他填充个红色长方形
<pre>
let sharedCanvas = wx.getSharedCanvas()
let context = sharedCanvas.getContext('2d')
context.fillStyle = 'red'
context.fillRect(0, 0, 300, 600)
</pre>


然后在主域上显示
<pre>
let openDataContext = wx.getOpenDataContext()
let sharedCanvas1 = openDataContext.canvas

let canvas1 = wx.createCanvas()
let context = canvas1.getContext('2d')
context.drawImage(sharedCanvas1, 10, 10)
</pre>

egret 好友排行榜demo https://github.com/egret-labs/egret-target-wxgame/tree/master/demos/openDataContext

 

posted @ 2019-11-13 01:00  newmiracle宇宙  阅读(455)  评论(0编辑  收藏  举报