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 开放域中 读取数据


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

4 下面最难的就是绘制排行榜了
首先开放域中调用默认的sharecanvas画布 给他填充个红色长方形

let sharedCanvas = wx.getSharedCanvas()
let context = sharedCanvas.getContext('2d')
context.fillStyle = 'red'
context.fillRect(0, 0, 300, 600)

然后在主域上显示

 let openDataContext = wx.getOpenDataContext()
    let sharedCanvas1 = openDataContext.canvas

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

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

原创文章如转载,请注明本文链接: http://newmiracle.cn/?p=3155

发表评论

电子邮件地址不会被公开。 必填项已用*标注