@@ -28,6 +28,8 @@ import { EventTarget } from '../../../cocos/core/event';
2828import { EventTouch , Touch as CCTouch } from '../../../cocos/input/types' ;
2929import { touchManager } from '../touch-manager' ;
3030import { InputEventType } from '../../../cocos/input/types/event-enum' ;
31+ import { systemInfo } from 'pal/system-info' ;
32+ import { OS } from '../../system-info/enum-type' ;
3133
3234export type TouchCallback = ( res : EventTouch ) => void ;
3335
@@ -114,7 +116,12 @@ export class TouchInputSource {
114116 private _dispatchEvent ( eventType : InputEventType , changedTouches : Touch [ ] , windowId : number ) : void {
115117 const handleTouches : CCTouch [ ] = [ ] ;
116118 const length = changedTouches . length ;
117- const windowSize = this . _windowManager . getWindow ( windowId ) . getViewSize ( ) as Size ;
119+ const window = this . _windowManager . getWindow ( windowId ) ;
120+ if ( window === null ) {
121+ return ;
122+ }
123+ const windowSize = window . getViewSize ( ) ;
124+ // const windowSize = this._windowManager.getWindow(windowId).getViewSize() as Size;
118125 for ( let i = 0 ; i < length ; ++ i ) {
119126 const changedTouch = changedTouches [ i ] ;
120127 const touchID = changedTouch . identifier ;
@@ -144,7 +151,10 @@ export class TouchInputSource {
144151 }
145152
146153 private _getLocation ( touch : globalThis . Touch , windowSize : Size ) : Vec2 {
147- const dpr = screenAdapter . devicePixelRatio ;
154+ let dpr = screenAdapter . devicePixelRatio ;
155+ if ( systemInfo . os === OS . WINDOWS ) { // 在windows下DPI变化时下发的是实际坐标
156+ dpr = 1 ;
157+ }
148158 const x = touch . clientX * dpr ;
149159 const y = windowSize . height - touch . clientY * dpr ;
150160 return new Vec2 ( x , y ) ;
0 commit comments