Open HopperGithub opened 1 year ago
hope getBoundingClientRect has a polyfill to support ClientRect ReturnType
eg:
function getBoundingClientRect() {
var rect = canvas.getBoundingClientRect();
return {
top: rect.top,
right: rect.right,
bottom: rect.bottom,
left: rect.left,
width: rect.width,
height: rect.height,
x: rect.x ?? rect.left,
y: rect.y ?? rect.top
};
}
my solution:
function getBoundingClientRectPolyfill() {
const rect = document.body.getBoundingClientRect()
if ('x' in rect && 'y' in rect) return
// @ts-ignore
Element.prototype._getBoundingClientRect = Element.prototype.getBoundingClientRect
Element.prototype.getBoundingClientRect = function (): DOMRect {
// @ts-ignore
const rect = Element.prototype._getBoundingClientRect.call(this)
rect.x = rect.x ?? rect.left
rect.y = rect.y ?? rect.top
return rect
}
}
call getBoundingClientRectPolyfill before the game init
This did not happen in my case. You can try it with chrome browser.
some real android devices could happen, using chrome devtool to showcase is unmeaning
Cocos Creator version
3.6.2
System information
Android < 8,Web Mobile
Issue description
Android < 8,touch event location will be recognized out of rect of canvas(GameCanvas). The returing is ClientRect and it's not having x and y properties.
sourcecode: cocos-engine/pal/input/web/touch-input.ts
sourcecode: cocos-engine/cocos/core/scene-graph/node-event-processor.ts
console.log
Relevant error log output
No response
Steps to reproduce
Minimal reproduction project
No response