Saturday, March 14, 2026

Decision scaling, devicePixelRatio – Cocos Creator


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

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

Is there any resolution now that I’m lacking?

I resolve this downside by altering the window.deviceRatioValue
window.devicePixelRatio = x
Simply to ensure the code run earlier than the appliance 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;

          // set off cc.view resize to use the brand new DPR
          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 should utilize. However I feel probably the most direct option to repair that is customise the engine. Attempt to replace this get devicePixelRatio perform

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisement -spot_img

Latest Articles