Files
ai_game/client/js/libs/weapp-adapter.js

38 lines
816 B
JavaScript
Raw Permalink Normal View History

/**
* 微信小游戏适配器
*/
// 获取系统信息
const systemInfo = wx.getSystemInfoSync();
const screenWidth = systemInfo.windowWidth;
const screenHeight = systemInfo.windowHeight;
const devicePixelRatio = systemInfo.pixelRatio;
// 创建主Canvas
const canvas = wx.createCanvas();
canvas.width = screenWidth * devicePixelRatio;
canvas.height = screenHeight * devicePixelRatio;
// 设置全局变量
GameGlobal.canvas = canvas;
GameGlobal.screenWidth = screenWidth;
GameGlobal.screenHeight = screenHeight;
GameGlobal.devicePixelRatio = devicePixelRatio;
// Image适配
GameGlobal.Image = function() {
return wx.createImage();
};
// Audio适配
GameGlobal.Audio = function() {
return wx.createInnerAudioContext();
};
export default {
canvas,
screenWidth,
screenHeight,
devicePixelRatio
};