Sunday, March 15, 2026

Decision scaling, devicePixelRatio – Cocos Creator


A parameter that may permit you to change the canvas (or render?) scale could 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 provide any outcomes and the canvas all the time adapts relying on the devicePixelRatio which I can’t change.

Is there any answer now that I’m lacking?

I remedy this drawback 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, nevertheless it doesn’t work on the goal system (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 screen.windowSize api you should use. However I believe probably the most direct technique 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