Closed lhkzh closed 3 years ago
是不是没有正确调用updateViewPort函数,这个是事件正确处理的大前提
https://wechat-miniprogram.github.io/minigame-canvas-engine/playground.html 这个例子里面。在pc上点击也有偏差。 js部分,修改了下随机内容的nickname部分标识,添加了click打印。 ` let xmlValue = window.xml.getValue(); let styleValue = window.style.getValue(); let styleObj = eval(styleValue);
// 创建mock数据 let item = { nickname: "zim5", rankScore: 1, avatarUrl: 'https://res.wx.qq.com/wechatgame/product/webpack/userupload/20191119/wegoing.jpeg', }; let datasource = { data :[], selfIndex: 1, self : item } for ( let i = 0; i < 20;i++ ) { var cp = JSON.parse(JSON.stringify(item)); cp.nickname = "zim"+(i+1); cp.rankScore = Math.floor(Math.random()*1000+1) datasource.data.push(cp); }
// 将XML模板编译成XML字符串 let tempFn = window.doT.template(xmlValue); let resultText = tempFn(datasource);
function init() { // getElementPagePosition为IDE内置函数 let pos = window.getElementPagePosition(canvas); // 每次初始化之前先执行清理逻辑保证内存不会一直增长 Layout.clear(); // 初始化引擎 Layout.init(resultText, styleObj);
//console.log(Layout)
// 设置canvas的尺寸和样式的container比例一致
canvas.width = Layout.renderport.width;
canvas.height = Layout.renderport.height;
canvas.style.width = 300 + 'px';
canvas.style.height = canvas.height / canvas.width * 300 + 'px';
Layout.updateViewPort({
x : pos.x,
y : pos.y,
width : canvas.offsetWidth,
height: canvas.offsetHeight,
});
Layout.layout(context);
var arr=Layout.getElementsByClassName('listItem');
arr.forEach((item,ii) => {
console.log(ii,JSON.stringify(item.realLayoutBox))
item.on('click', (e) => {
console.log( item.children[2].value);
//console.log("listItem:", item);
});
});
}
init(); window.onresize = init;`
在电脑上手机上都有偏差,手机上因屏幕不同偏差不同
请问这个问题解决了吗
已经修复
在电脑上手机上都有偏差,手机上因屏幕不同偏差不同