cocos / cocos-engine

Cocos simplifies game creation and distribution with Cocos Creator, a free, open-source, cross-platform game engine. Empowering millions of developers to create high-performance, engaging 2D/3D games and instant web entertainment.
https://www.cocos.com/en/creator
Other
7.21k stars 1.83k forks source link

Add screen size and resolution APIs #15349

Open pandamicro opened 1 year ago

pandamicro commented 1 year ago

Use Case

Screen size API is important for Desktop apps, and dynamic adjust should be available at runtime. Passive screen resize now involves back buffer size, all cameras and re-adaptation of UI, but developers could also benefits from active screen resize APIs.

On the other hand, even with constant screen size, developers can also have performance benefit if we allow user to customize its resolution. This is important on mobile devices and web.

Problem Description

Currently we only have root.resize API, but it's too low level, we need Screen level customization which could actively handle all relative changes.

Request received form the forum too: https://discuss.cocos2d-x.org/t/feature-request-configure-renderer-resolution/58888

Proposed Solution

Proposed APIs

How it works

No response

Alternatives Considered

Nothing to add

Additional Information

No response

minggo commented 1 year ago

On the other hand, even with constant screen size, developers can also have performance benefit if we allow user to customize its resolution.

Could you please describe more about resolution? Did you mean change the dpi or the same effect as root.resize()?

pandamicro commented 1 year ago

DPI is physical property of the device screen, we can't change that. But we can change back buffer size and trigger all adaptation afterward, back buffer size can be changed with root.resize, but there are two main issues:

So I suggest we use the commented API resolutionScale in screen, it's a resolution ratio controllable by the developer. So he can reduce the back buffer size by that ratio and make our systems adapt to the new size

minggo commented 1 year ago

Screen is in pal, it is a very low level in engine architect. So it can not depend on upper level. If want to add the API here, then it can only trigger a event, and other modules listen and handle the event. Or can add the feature in upper level, but i have not idea which module to add it currently, need more discussion.