public setFrameSize (width: number, height: number) {
const dpr = screenAdapter.devicePixelRatio;
screen.windowSize = new Size(width * dpr, height * dpr);
* @en Returns the visible area size of the view port.
* @zh 返回视图窗口可见区域尺寸。
public getVisibleSize (): Size {
return new Size(this._visibleRect.width, this._visibleRect.height);
* @en Returns the visible area size of the view port.
* @zh 返回视图窗口可见区域像素尺寸。
public getVisibleSizeInPixel (): Size {
return new Size(this._visibleRect.width * this._scaleX,
this._visibleRect.height * this._scaleY);
是 screen.windowSize,可以关注下接口注释说明,废弃的接口一般会有替代方案说明
screen 需要从 cc 模块导入,如果访问到 screen.windowSize 是 undefined,可能是使用了 web 标准的 window.screen 对象,这个不是从 cc 模块导入的。
应该像这样导入 screen 对象:
import { screen } from 'cc'
未来我们希望减少对 web feature 的依赖,提供更多平台通用的接口
像上边提到的 window.screen 就是一个 web 接口,不是引擎提供的
抱歉这里是会造成一些使用上的歧义
好的 确实没注意到要 import screen
我试了下在web下 getFrameSize 和 screen.windowSize 获得的大小不相等 但长宽比是一致的
有办法获得和原本 getFrameSize 一样的大小吗?
谢谢官方人员回答 
getFrameSize 获取到的是 frame 的 css size,这个是 web 行为,后续我们希望废弃 web 相关特性的接口
当然我们也不希望改变这个接口的行为,这会破坏接口兼容性
windowSize 相当于 css width/height * devicePixelRatio,这个是真实的物理像素,也是我们希望提供给开发者的屏幕宽高,如果需要保持一致的话,只需要做一个除法就好了
let frameWidth = screen.windowSize.width / screen.devicePixelRatio
let frameHeight = screen.windowSize.height / screen.devicePixelRatio