mirror of
https://github.com/smallmain/cocos-enhance-kit.git
synced 2025-10-09 21:25:24 +00:00
[adapters] 增加小游戏适配部分源码
This commit is contained in:
12
adapters/platforms/taobao/res/pages/index/index.axml
Normal file
12
adapters/platforms/taobao/res/pages/index/index.axml
Normal file
@@ -0,0 +1,12 @@
|
||||
<view class="canvas-element" style="flex-direction:row;display:flex;flex:1;background-color:rgba(0,0,0,1);">
|
||||
<canvas
|
||||
id="GameCanvas"
|
||||
type="webgl"
|
||||
onReady="canvasOnReady"
|
||||
style="width:100%;height:100%;"
|
||||
onTouchStart="onTouchStart"
|
||||
onTouchCancel="onTouchCancel"
|
||||
onTouchEnd="onTouchEnd"
|
||||
onTouchMove="onTouchMove"
|
||||
></canvas>
|
||||
</view>
|
66
adapters/platforms/taobao/res/pages/index/index.js
Normal file
66
adapters/platforms/taobao/res/pages/index/index.js
Normal file
@@ -0,0 +1,66 @@
|
||||
var touchstartCB;
|
||||
var touchcancelCB;
|
||||
var touchendCB;
|
||||
var touchmoveCB;
|
||||
|
||||
function handleTouchEvent (event) {
|
||||
let changedTouches = event.changedTouches;
|
||||
if (changedTouches) {
|
||||
for (let touch of changedTouches) {
|
||||
touch.clientX = touch.x;
|
||||
touch.clientY = touch.y;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Page({
|
||||
onReady () {
|
||||
__globalAdapter.onTouchStart = function (cb) {
|
||||
touchstartCB = cb;
|
||||
}
|
||||
__globalAdapter.onTouchCancel = function (cb) {
|
||||
touchcancelCB = cb;
|
||||
}
|
||||
__globalAdapter.onTouchEnd = function (cb) {
|
||||
touchendCB = cb;
|
||||
}
|
||||
__globalAdapter.onTouchMove = function (cb) {
|
||||
touchmoveCB = cb;
|
||||
}
|
||||
},
|
||||
onError (err) {
|
||||
console.error('error in page: ', err);
|
||||
},
|
||||
onTouchStart (event) {
|
||||
handleTouchEvent(event);
|
||||
touchstartCB && touchstartCB(event);
|
||||
},
|
||||
onTouchCancel (event) {
|
||||
handleTouchEvent(event);
|
||||
touchcancelCB && touchcancelCB(event);
|
||||
},
|
||||
onTouchEnd (event) {
|
||||
handleTouchEvent(event);
|
||||
touchendCB && touchendCB(event);
|
||||
},
|
||||
onTouchMove (event) {
|
||||
handleTouchEvent(event);
|
||||
touchmoveCB && touchmoveCB(event);
|
||||
},
|
||||
canvasOnReady () {
|
||||
my.createCanvas({
|
||||
id:'GameCanvas',
|
||||
success(canvas){
|
||||
if (!canvas) {
|
||||
console.error('failed to create canvas.');
|
||||
return;
|
||||
}
|
||||
$global.screencanvas = canvas;
|
||||
$global.__cocosCallback();
|
||||
},
|
||||
fail (err) {
|
||||
console.error('failed to init on screen canvas', err)
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
1
adapters/platforms/taobao/res/pages/index/index.json
Normal file
1
adapters/platforms/taobao/res/pages/index/index.json
Normal file
@@ -0,0 +1 @@
|
||||
{}
|
Reference in New Issue
Block a user