Different fill mode for desktop

Is it possible to have the fill mode “Keep aspect ratio” for desktop and “Fill window” for mobile devices?

Hi,
Yes its possible,

 setFillMode() {
        if(pc.platform.mobile)
        {
            this.app.setCanvasFillMode(pc.FILLMODE_FILL_WINDOW);
        }
    }

thanks for answering! … but where I should place and call that function? I’m using the editor

Call it in the initialize function of any script.

I will add an answer here, instead of Discord:

As @Saad_Haider mentioned you should add it in the initialize() method. For example:

Script.attributes.initialize = function() {
    this.setFillMode();
};
Script.attributes.setFillMode = function() {
    if (pc.platform.mobile) {
        this.app.setCanvasFillMode(pc.FILLMODE_FILL_WINDOW);
    }
};
1 Like

thanks!

I was getting a black stripe above

I fixed that adding those lines:

if(pc.platform.mobile) {
       
          this.app.setCanvasFillMode(pc.FILLMODE_FILL_WINDOW);
        
          document.getElementById("application-canvas").style.height = "100%";
          document.getElementById("application-canvas").style.margin = 0;
}

I’m wondering if script initialise is too late and perhaps adding it the loading script is better or even earlier?

no, same problem if I do it in the preload script

Hi there! Has anyone found the solution for that black bar issue? I am getting the same problem

@Cheburashka Please see this thread: [SOLVED] Trying to switch between Fill Mode to Keep Aspect ratio