微信小遊戲遊戲圈處理(cocos creator處理)
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
}
});
如有問題,歡迎指正,共通學習。