微信小游戏权限
微信小游戏权限问题
微信公众平台 https://mp.weixin.qq.com/
- 数据隐私协议:需要去微信开发者后台开启用户隐私保护指引
,并且开启授权弹窗提醒否则真机测试的时候有时候会授权成功,有时候会授权失败,都是泪 😭😭😭
- 用户信息授权按钮:因为微信小程序限制只能由先创建授权按钮然后点击后授权。因此,需要把授权按钮做成一个透明的按钮覆盖在cocos的Node上(或者在进入游戏时创建一个全屏透明的授权按钮)
微信用户权限按钮的设置在指定位置问题
当进行显示排行榜时需要创建一个透明的按钮在显示排行榜按钮上面,这样点击按钮时首先会调用用户信息授权,拿到用户的昵称、头像、openid,然后隐藏授权按钮即可
但当查看微信api时会发现授权按钮需要传一个位置信息,但是在cocos中位置怎么设置都不对?
以项目分辨率设置 640x1136
自适应采用 fit width为例
设备为 iphone 13pro(390x844 | Dpr:3)
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| const ratio = screen.devicePixelRatio
const scale = view.getScaleX()
const factor = scale / ratio
const width = btnSize.width * factor; const height = btnSize.height * factor;
const top = winSize.height / ratio - height - (80 * factor) const left = winSize.width / ratio - width - (33 * factor)
|
最终完整代码如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| const btnNodeUiTransform = btnNode.getComponent(UITransform);
const btnSize = btnNodeUiTransform; const winSize = screen.windowSize;
const ratio = screen.devicePixelRatio const scale = view.getScaleX() const factor = scale / ratio
const width = btnSize.width * factor; const height = btnSize.height * factor;
const top = winSize.height / ratio - height - (80 * factor) const left = winSize.width / ratio - width - (33 * factor)
this.userInfoButton = wx.createUserInfoButton({ type: 'text', text: '', style: { left: left, top: top, width: width, height: height, backgroundColor: 'rgba(255, 255, 255, 0)', } })
this.userInfoButton.onTap((res) => { if (res.userInfo) { console.log(res.userInfo) this.userInfoButton.hide(); } else { Toast.toast('用户信息授权失败') } });
|
微信排行榜开放子域绘制问题
- 遇到排行榜渲染闪烁的问题?
cocos 开放子域模板中minigame-canvas-engine库的版本为旧的,请去github找到最新代码替换到engine.js文件中