mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-05 19:12:40 +08:00
33c0aa1bf3
* use wechatprogram subpackge default and speedup launch time * move gl.texSubImage2D adapater to PAL * refine * add getApp declare * fix texture rendering in device * move bundle require insert to load-module
69 lines
2.1 KiB
JavaScript
69 lines
2.1 KiB
JavaScript
var GameGlobal = getApp().GameGlobal;
|
|
exports.adapt = function (canvas, width, height) {
|
|
GameGlobal.canvas = canvas;
|
|
GameGlobal.WXWebAssembly = WXWebAssembly;
|
|
GameGlobal.requestAnimationFrame = GameGlobal.canvas.requestAnimationFrame || globalThis.setTimeout;
|
|
GameGlobal.cancelAnimationFrame = GameGlobal.canvas.cancelAnimationFrame || globalThis.setTimeout;
|
|
GameGlobal.setTimeout = globalThis.setTimeout;
|
|
GameGlobal.setInterval = globalThis.setInterval;
|
|
GameGlobal.clearTimeout = globalThis.clearTimeout;
|
|
GameGlobal.clearInterval = globalThis.clearInterval;
|
|
|
|
let isFirstCall = true;
|
|
|
|
wx.createCanvas = function () {
|
|
console.log('wx.createCanvas called');
|
|
if (isFirstCall) {
|
|
isFirstCall = false;
|
|
return canvas;
|
|
} else {
|
|
return wx.createOffscreenCanvas({type:"2d", width: width, height: height});
|
|
}
|
|
}
|
|
|
|
wx.createImage = function () {
|
|
console.log('wx.creatImage in miniapp-adapter')
|
|
let image = canvas.createImage();
|
|
return image;
|
|
}
|
|
|
|
wx.onTouchStart = function (cb) {
|
|
GameGlobal._touchStart = function (event) {
|
|
handleTouchEvent(event);
|
|
cb(event);
|
|
};
|
|
};
|
|
wx.onTouchMove = function (cb) {
|
|
GameGlobal._touchMove = function (event) {
|
|
handleTouchEvent(event);
|
|
cb(event);
|
|
};
|
|
};
|
|
wx.onTouchEnd = function (cb) {
|
|
GameGlobal._touchEnd = function (event) {
|
|
handleTouchEvent(event);
|
|
cb(event);
|
|
};
|
|
};
|
|
wx.onTouchCancel = function (cb) {
|
|
GameGlobal._touchCancel = function (event) {
|
|
handleTouchEvent(event);
|
|
cb(event);
|
|
};
|
|
};
|
|
|
|
function handleTouchEvent (event) {
|
|
let changedTouches = event.changedTouches;
|
|
if (changedTouches) {
|
|
for (let touch of changedTouches) {
|
|
touch.clientX = touch.x;
|
|
touch.clientY = touch.y;
|
|
}
|
|
}
|
|
}
|
|
|
|
//TODO: use wx.onDeviceMotionChange to instead
|
|
wx.onDeviceOrientationChange = function () {
|
|
}
|
|
};
|