Tuesday, January 6, 2026
spot_img

Decision scaling, devicePixelRatio – Cocos Creator


A parameter that will will let you change the canvas (or render?) scale can be very useful in optimizing/adapting to totally different screens and {hardware}.

Calling totally different strategies from cc.view for downgrading decision doesn’t appear to provide any outcomes and the canvas all the time adapts relying on the devicePixelRatio which I can’t change.

Is there any resolution now that I’m lacking?

I remedy this downside by altering the window.deviceRatioValue
window.devicePixelRatio = x
Simply to ensure the code run earlier than the applying began. Personally I put it within the html, earlier than scripts being imported.



1 Like

It appears to work on my PC, but it surely doesn’t work on the goal machine (LG TV, WebOS, chromium ~53).

window.devicePixelRatio for learn solely there?

Here’s a workaround that appears to work

(() => {
      (() => {
      let devicePixelRatio = 1;
      Object.defineProperty(window, 'devicePixelRatio', {
        get: () => devicePixelRatio,
        set: (worth) => {
          console.log('devicePixelRatio set to', worth);
          devicePixelRatio = worth;

          if(window.cc && cc.view){
            const canvasSize = cc.view.getCanvasSize();
            cc.view._updateAdaptResult(canvasSize.width, canvasSize.peak);
          }
        },
        configurable: true,
      });
    })();



1 Like

Good hack.
After extra inspecting the doc. There’s a display.windowSize api you need to use. However I feel probably the most direct solution to repair that is customise the engine. Attempt to replace this get devicePixelRatio operate

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisement -spot_img

Latest Articles