微信小游戏游戏圈处理(cocos creator处理)

1. 创建游戏圈,具体可以参考:https://developers.weixin.qq.com/minigame/dev/tutorial/open-ability/game-club.html

2. 把游戏圈放到指定的位置方案(假如需要放到页面上指定按钮GameClubButton的位置上,页面的锚点是(0,0)左下角 )

2.1 获取GameClubButton的坐标(x, y)

var x = this.GameClubButton.node.x;

var y = this.GameClubButton.node.y;

2.2 获取逻辑屏幕宽高

let windowSize = cc.view.getVisibleSize();

2.3 得出该位置对应于左上的比例

var leftRatio = this.GameClubButton.x / windowSize.width;

var topRatio = 1 - this.GameClubButton.y / windowSize.height;

2.4 获得实际手机的屏幕宽高

let sysInfo = wx.getSystemInfoSync();

2.5 得出应该放置的对应于left和top的距离

var leftPos = sysInfo.windowWidth * leftRatio;

var topPos = sysInfo.windowHeight * topRatio;

2.6 创建游戏圈按钮

clubButton = wx.createGameClubButton({

    icon: 'light',

    style: {

        left: leftPos - 20, // 之所以要减20,是因为clubButton的锚点在左上角

        top: topRos - 20, // 之所以要减20,是因为clubButton的锚点在左上角 

        width: 40,

        height: 40

    }

});

如有问题,欢迎指正,共通学习。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值